For example:
https://stackoverflow.com/questions/3439709/how-to-cater-for-
anonymoususer-when-filtering-based-on-user
I think this deserves a better error message, for example something like:
`ValueError("Can't filter User field with AnonymousUser")`.
--
Ticket URL: <https://code.djangoproject.com/ticket/29782>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* owner: nobody => ramonsaraiva
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:1>
* version: 2.1 => master
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
Yep. Great. Better error messages FTW! 🙂
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:2>
Comment (by Ramon Saraiva):
Still trying to understand what piece of code would be responsible for
this behaviour.
I wonder if overwriting `AnonymousUser`'s `__int__` would be too naive?
Since `AnonymousUser` is not inheriting from `Model`, it happens that its
instance is passed all the way over to the field `get_prep_value` and then
`int(value -> AnonymousUser)` is called.
Any guidance/idea about what should be responsible for doing this
validation?
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:3>
* easy: 1 => 0
Comment:
An obvious implementation doesn't come to mind. I'm not sure if it's
feasible.
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:4>
Comment (by Adam (Chainz) Johnson):
{{AnonymousUser.__int__}} might work, if you make the error message more
generic like {{TypeError("Cannot cast AnonymousUser to int. Are you trying
to use it in place of User?")}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:5>
Comment (by Ramon Saraiva):
Ok, I'll work on that patch and we can continue from there.
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:6>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10443 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"2349cbd909c387d2d05cda20ce8d0c63c1b1c6c4" 2349cbd9]:
{{{
#!CommitTicketReference repository=""
revision="2349cbd909c387d2d05cda20ce8d0c63c1b1c6c4"
Fixed #29782 -- Added better error message when filtering queryset with
AnonymousUser.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29782#comment:8>