Fixed #29782 -- Added better error message when filtering queryset with AnonymousUser.
This commit is contained in:
parent
18098d261f
commit
2349cbd909
1
AUTHORS
1
AUTHORS
|
@ -694,6 +694,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Ramez Ashraf <ramezashraf@gmail.com>
|
Ramez Ashraf <ramezashraf@gmail.com>
|
||||||
Ramin Farajpour Cami <ramin.blackhat@gmail.com>
|
Ramin Farajpour Cami <ramin.blackhat@gmail.com>
|
||||||
Ramiro Morales <ramiro@rmorales.net>
|
Ramiro Morales <ramiro@rmorales.net>
|
||||||
|
Ramon Saraiva <ramonsaraiva@gmail.com>
|
||||||
Ram Rachum <ram@rachum.com>
|
Ram Rachum <ram@rachum.com>
|
||||||
Randy Barlow <randy@electronsweatshop.com>
|
Randy Barlow <randy@electronsweatshop.com>
|
||||||
Raphaël Barrois <raphael.barrois@m4x.org>
|
Raphaël Barrois <raphael.barrois@m4x.org>
|
||||||
|
|
|
@ -383,6 +383,9 @@ class AnonymousUser:
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return 1 # instances always return the same hash value
|
return 1 # instances always return the same hash value
|
||||||
|
|
||||||
|
def __int__(self):
|
||||||
|
raise TypeError('Cannot cast AnonymousUser to int. Are you trying to use it in place of User?')
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
|
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
|
||||||
|
|
||||||
|
|
|
@ -345,6 +345,14 @@ class AnonymousUserTests(SimpleTestCase):
|
||||||
def test_hash(self):
|
def test_hash(self):
|
||||||
self.assertEqual(hash(self.user), 1)
|
self.assertEqual(hash(self.user), 1)
|
||||||
|
|
||||||
|
def test_int(self):
|
||||||
|
msg = (
|
||||||
|
'Cannot cast AnonymousUser to int. Are you trying to use it in '
|
||||||
|
'place of User?'
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
|
int(self.user)
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
with self.assertRaisesMessage(NotImplementedError, self.no_repr_msg):
|
with self.assertRaisesMessage(NotImplementedError, self.no_repr_msg):
|
||||||
self.user.delete()
|
self.user.delete()
|
||||||
|
|
Loading…
Reference in New Issue