#18352: You can't use AnonymousUser in the database API
------------------------------+--------------------------------------
     Reporter:  teolicy       |                    Owner:  nobody
         Type:  New feature   |                   Status:  new
    Component:  contrib.auth  |                  Version:  1.4
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Unreviewed
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+--------------------------------------
Changes (by teolicy):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Comment:

 Excuse me if I'm rambling, a couple more thoughts:
 1. Storing the new `AnonymousUser` in the database will of course have its
 share of issues, like making it potentially mutable (yikes!) and needing
 adjustments to `is_authenticated()` and so. I think all sane usecases can
 be solved by overriding `.save()` and `.delete()`, and bulk updates of the
 `User` table are probably very rare and done very carefully.
 2. Perhaps the right setting is `AUTH_NEW_STYLE_ANONYMOUS_PK=0` (or
 similar). That way, you can instantiate `AnonymousUser` for `request.user`
 without hitting the database, by doing something like
 `User(pk=AUTH_NEW_STYLE_ANONYMOUS_PK, first_name=...)`.
 3. The reason I'm leaning towards making `AnonymousUser` a real database
 object (a null object, if you will), is that I fear it's the only sane way
 to make it 100.0% compatible with the ORM without adding ugly special
 cases all over the code (hint: currently, we lay the onus of all these
 special cases on the user, which might not be as careful as framework
 authors must be). However, I think the `AnonymousUser` compatibility
 situation can and should be improved even if my idea of using an actual
 `AnonymousUser` record in the database is not the right way to go about
 doing this.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18352#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to