TransactionManagementError - This is forbidden when an 'atomic' block is active - python

While upgrading my project from django 1.5.1 to 1.6.5, I am facing this weird issue.
This is forbidden when an 'atomic' block is active.
I am aware of the Database Transaction changes for django 1.6 and made the setting changes accordingly. Works for most part, except when request.user object is accessed.
The code, for instance:
with transaction.atomic():
if hasattr(request, 'user') and getattr(request.user, 'id', None):
#blah
Here is the stacktrace:
Environment:
Request Method: GET
Request URL: <domain>/api/v1/browser_id/
Django Version: 1.6.5
Python Version: 2.7.3
<Installed Applications & Middlewares snipped for brevity>
Traceback:
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
371. return func(*args, **kwargs)
File "/home/kravindra/workspace/puppysite/puppy/kennel/views/etag_session.py" in browser_id
43. if hasattr(request, 'user') and getattr(request.user, 'id', None):
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/utils/functional.py" in inner
213. self._setup()
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/utils/functional.py" in _setup
298. self._wrapped = self._setupfunc()
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in <lambda>
18. request.user = SimpleLazyObject(lambda: get_user(request))
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py" in get_user
10. request._cached_user = auth.get_user(request)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in get_user
140. user_id = request.session[SESSION_KEY]
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
47. return self._session[key]
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session
173. self._session_cache = self.load()
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/cached_db.py" in load
52. self.create()
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in create
40. self.save(must_create=True)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/cached_db.py" in save
62. super(SessionStore, self).save(must_create)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
63. obj.save(force_insert=must_create, using=using)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/models/base.py" in save
545. force_update=force_update, update_fields=update_fields)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
582. update_fields=update_fields, raw=raw, using=using)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
185. response = receiver(signal=self, sender=sender, **named)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/transaction.py" in inner
430. with self:
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/transaction.py" in __enter__
422. self.entering(self.using)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/transaction.py" in entering
483. enter_transaction_management(using=using)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/transaction.py" in enter_transaction_management
70. get_connection(using).enter_transaction_management(managed, forced)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/backends/__init__.py" in enter_transaction_management
287. self.validate_no_atomic_block()
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/db/backends/__init__.py" in validate_no_atomic_block
367. "This is forbidden when an 'atomic' block is active.")
Exception Type: TransactionManagementError at /api/v1/browser_id/
Exception Value: This is forbidden when an 'atomic' block is active.
Looking at the stacktrace,
/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/contrib/sessions/backends/cached_db.py in load
self.create() ...
▼ Local vars
Variable Value
e
DoesNotExist('Session matching query does not exist.',)
self
<django.contrib.sessions.backends.cached_db.SessionStore object at 0x7f61d401c6d0>
data
None
SessionStore raises an exception.
Using POSTGRES as the backend database.
The backend session store related settings are:
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' #which is persistent storage
ATOMIC_REQUESTS = True
Any pointers on how to fix this issue?
I found that there are a bunch of Questions on SO, and blogposts that address TransactionManagementError issue in general, but nothing to address this issue in particular

From the traceback it looks like one of your post_save signal receiver is still using one of the following deprecated transaction APIs:
transaction.Transaction
transaction.autocommit
transaction.commit_on_success
transaction.commit_manually
commit_on_success_unless_managed
Make sure to replace it with a transaction.atomic instance instead and your issue should go away.
Let me know if you have trouble finding the culprit receiver.

Related

Why do I get 'NoneType' object is not callable when trying to delete item with m2m relations?

I'm writing an app to represent some systems : some equipments will contain hardware articles, for exemple a server will contain hard drives.
For CRUD operations i'm using DRF ModelViewSet (nothing overriden).
When I delete an equipment which m2m relation is not set it works fine, but I get an error when it is.
Here is a simplified version of the model scheme.
class Hardware(models.Model):
equipment = models.ManyToManyField('Equipment', blank=True, through='HardwareEQ')
# attributes
class HardwareEQ(models.Model):
hardware = models.ForeignKey(Hardware, on_delete=models.CASCADE)
equipment = models.ForeignKey(Equipment, on_delete=models.CASCADE)
# relation attributes
Below is full traceback.
Traceback:
File "C:\Users\USER\Envs\venv\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\viewsets.py" in view
103. return self.dispatch(request, *args, **kwargs)
File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\views.py" in dispatch
483. response = self.handle_exception(exc)
File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\views.py" in handle_exception
443. self.raise_uncaught_exception(exc)
File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\views.py" in dispatch
480. response = handler(request, *args, **kwargs)
File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\mixins.py" in destroy
93. self.perform_destroy(instance)
File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\mixins.py" in perform_destroy
97. instance.delete()
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\base.py" in delete
918. collector.collect([self], keep_parents=keep_parents)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in collect
224. field.remote_field.on_delete(self, field, sub_objs, self.using)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in CASCADE
16. source_attr=field.name, nullable=field.null)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in collect
220. sub_objs = self.related_objects(related, batch)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in related_objects
236. **{"%s__in" % related.field.name: objs}
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\query.py" in filter
892. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
910. clone.query.add_q(Q(*args, **kwargs))
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\sql\query.py" in add_q
1290. clause, _ = self._add_q(q_object, self.used_aliases)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\sql\query.py" in _add_q
1318. split_subq=split_subq, simple_col=simple_col,
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\sql\query.py" in build_filter
1202. value = self.resolve_lookup_value(value, can_reuse, allow_joins, simple_col)
File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\sql\query.py" in resolve_lookup_value
1037. sub_value.resolve_expression(self, reuse=can_reuse, allow_joins=allow_joins)
Exception Type: TypeError at /Sycoma2/ensemble/2/
Exception Value: 'NoneType' object is not callable
Edit : add information
To perform the deletion, I call the hardareEN view using ajax request.
The view is a ModelViewSet, like below :
class HardwareENViewSet(viewsets.ModelViewSet):
queryset = HardwareEN.objects.all()
serializer_class = HardwareENSerializer
The serializer looks like this :
class HardwareENSerializer(VerboseSerializer):
class Meta:
model = HardwareEN
fields = '__all__'
def to_representation(self, instance):
"""
Add hardware data
:param instance:
:return:
"""
data = super().to_representation(instance)
for key, value in HardwareSerializer(instance.hardware).data.items():
try:
if not data[key]:
data[key] = value
except KeyError:
data[key] = value
return data
For information, I tried removing the to_representation override, without more success.
The problem was that I overrode the __getattr__ method of HardwareEN model but forgot to add AttributeError for non-existing attributes. Therefore, when fetching the model attributes, the framework didnt get an attribute error when needed.

Django allauth register button has suddenly stopped working

I have never had any problems with it previously but when I clicked on it just then, it did not do anything. However my login works fine.
I'm running a custom signup class (so I can include google recaptcha) - this has already been tried and tested to work:
class AllauthSignupForm(forms.Form):
captcha = ReCaptchaField()
class Meta:
model = User
def signup(self, request, user):
""" Required, or else it throws deprecation warnings """
pass
I believe I may have altered the source code in django-allauth/blob/master/allauth/account/forms.py however I can't figure out what I changed. So I tried copy pasting the whole forms.py on github to my forms.py, and that returned this error:
Traceback:
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/zorgan/Desktop/vorsso/venvor/draft1/views.py" in boxes_view
116. return render(request, 'boxes.html', context)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/shortcuts.py" in render
30. content = loader.render_to_string(template_name, context, request, using=using)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/template/loader.py" in render_to_string
68. return template.render(context, request)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/template/backends/django.py" in render
66. return self.template.render(context)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/template/base.py" in render
205. with context.bind_template(self):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py" in __enter__
59. return next(self.gen)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/django/template/context.py" in bind_template
263. updates.update(processor(self.request))
File "/Users/zorgan/Desktop/project/app/draft1/processors.py" in everywhere
12. allauth_signup = SignupForm(request.POST or None)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/allauth/account/forms.py" in __init__
364. super(SignupForm, self).__init__(*args, **kwargs)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/allauth/account/forms.py" in __init__
321. getattr(self, 'field_order', None) or default_field_order)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/allauth/utils.py" in set_form_field_order
252. for f in fields_order)
File "/Users/zorgan/Desktop/postr1/lib/python3.5/site-packages/allauth/utils.py" in <genexpr>
252. for f in fields_order)
Exception Type: KeyError at /news/
Exception Value: 'email2'
so I believe I may have tampered something with email2.
Any idea what the problem is?
EDIT
Ok when I remove captcha = ReCaptchaField() from my custom form the register works. Any idea why?
EDIT2
So it seems it works on chrome but not firefox. Some problem with google recaptcha not working on firefox.

Keyerror u'_source' in django haystack with Elasticsearch backend

I am getting a Keyerror whenever I specify .values() with SearchQuerySet in django Haystack. For e.g.
required_output = SearchQuerySet()[:10]
works fine. But whenever, I do the following, its throwing KeyError everytime.
required_output = SearchQuerySet().values('title', 'slug')[:10]
Here's the Trackback of the error:
Traceback:
File "/home/project_env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/home/project_env/myproject/source/apps/Project/views.py" in get
151. context = self.get_context_data(object=self.object)
File "/home/project_env/myproject/source/apps/Project/views.py" in get_context_data
108. context['related_project'] = SearchQuerySet().values('title')[:10]
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in __getitem__
266. self._fill_cache(start, bound)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in _fill_cache
656. return super(ValuesListSearchQuerySet, self)._fill_cache(start, end, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/query.py" in _fill_cache
166. results = self.query.get_results(**kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/__init__.py" in get_results
645. self.run(**kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in run
918. results = self.backend.search(final_query, **search_kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/__init__.py" in wrapper
35. return func(obj, query_string, *args, **kwargs)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in search
504. distance_point=kwargs.get('distance_point'), geo_sort=geo_sort)
File "/home/project_env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py" in _process_results
580. source = raw_result['_source']
What version of django-haystack are you using? It looks like there is an open issue for this on the django-haystack GitHub. There is also a patch that should fix it. Looks like you'll have to either wait for the merge, or patch it locally.
Issue #1019
Pull Request #1020

SMTPConnectError when using Django

I'm using django-registration for handling of users registration. I tried to signup in order to test it, after testing it, I got this error
SMTPConnectError at /accounts/register/
Being trying to find a solution yet no success!
Full Traceback
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\registration\views.py" in register
187. new_user = backend.register(request, **form.cleaned_data)
File "C:\Python27\lib\site-packages\registration\backends\default\__init__.py" in register
79. password, site) File "C:\Python27\lib\site-packages\django\db\transaction.py" in inner
209. return func(*args, **kwargs) File "C:\Python27\lib\site- packages\registration\models.py" in create_inactive_user
85. registration_profile.send_activation_email(site)
File "C:\Python27\lib\site-packages\registration\models.py" in send_activation_email
264. self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py" in email_user
374. send_mail(subject, message, from_email, [self.email])
File "C:\Python27\lib\site-packages\django\core\mail\__init__.py" in send_mail
61. connection=connection).send()
File "C:\Python27\lib\site-packages\django\core\mail\message.py" in send
248. return self.get_connection(fail_silently).send_messages([self])
File "C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py" in send_messages
85. new_conn_created = self.open()
File "C:\Python27\lib\site-packages\django\core\mail\backends\smtp.py" in open
48. local_hostname=DNS_NAME.get_fqdn())
File "C:\Python27\lib\smtplib.py" in __init__
251. raise SMTPConnectError(code, msg)
Exception Type: SMTPConnectError at /accounts/register/
Exception Value: (451, 'Request action aborted on MFE proxy, SMTP server is not available.')
In Settings.py
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS=True
EMAIL_HOST='smtp.test.com'
EMAIL_HOST_USER='test#test.com'
EMAIL_HOST_PASSWORD='f88lm'
EMAIL_PORT=587
DEFAULT_FROM_EMAIL = 'test#test.com'
SERVER_EMAIL = 'test#test.com'
Of course there is an error, you have given details for an SMPT server that doesn't exist so Django can't connect to it when trying to send email. While developing, either use the dummy email backend:
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
or run a test email server locally.
The problem is from my domain email hosting provider. Thanks!

using request.user.is_authenticated() in Django project

When I try to do request.user.is_authenticated() I get a ValidationError: None is not a valid ObjectId
I'm trying to track down the problem but I do not what's causing it.I'm using MongoEngine (and MongoDB.)
I have the following in my settings.py:
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
'rs.claimutil.auth_backend.ClaimAuthBackend',
)
SESSION_ENGINE = 'mongoengine.django.sessions'
This is what I get:
Traceback: File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py"
in get_response
111. response = callback(request, *callback_args, **callback_kwargs) File "/Users/bastiano/Documents/ttsf/rsrv/views.py" in reserve
11. if not request.user.is_authenticated(): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py"
in inner
184. self._setup() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py"
in _setup
248. self._wrapped = self._setupfunc() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/middleware.py"
in
16. request.user = SimpleLazyObject(lambda: get_user(request)) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/middleware.py"
in get_user
8. request._cached_user = auth.get_user(request) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/init.py"
in get_user
101. user = backend.get_user(user_id) or AnonymousUser() File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/django/auth.py"
in get_user
149. return User.objects.with_id(user_id) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in with_id
923. return self.filter(pk=object_id).first() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in first
843. result = self[0] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in getitem
1136. return self._document._from_son(self._cursor[key]) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in _cursor
579. self._cursor_obj = self._collection.find(self._query, File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in _query
375. self._mongo_query = self._query_obj.to_query(self._document) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in to_query
202. query = query.accept(QueryCompilerVisitor(document)) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in accept
267. return visitor.visit_query(self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in visit_query
159. return QuerySet._transform_query(self.document, **query.query) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/queryset.py"
in _transform_query
720. value = field.prepare_query_value(op, value) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/base.py"
in prepare_query_value
455. return self.to_mongo(value) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/base.py"
in to_mongo
451. self.error(unicode(e)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/base.py"
in error
203. raise ValidationError(message, errors=errors, field_name=field_name)
Exception Type: ValidationError at /rs/claim Exception Value: None is
not a valid ObjectId
Any ideas why this is happening? Is there an easier way to do user authentication in Django + MongoDB?
Views.py:
def claim(request):
if request.method == 'GET':
if not request.user.is_authenticated():
return shortcuts.redirect('rs/login')
all_b = dbutil.get_b(all=True)
return shortcuts.render_to_response('rs/index.html',
{'all_b':all_b},
context_instance=template.RequestContext(request))
elif request.method == 'POST':
The rest of the view is omitted for simplicity. I used ipdb to debug it and if not request.user.is_authenticated() is the problem. I tried using django.contrib.auth.decorators.login_required.decorator before, but it, too, failed.
Try to update your mongoengine to the latest version. In master, it is
def get_user(userid):
"""Returns a User object from an id (User.id). Django's equivalent takes
request, but taking an id instead leaves it up to the developer to store
the id in any way they want (session, signed cookie, etc.)
"""
# your installed mongoengine might not include following two lines
if not userid:
return AnonymousUser()
return MongoEngineBackend().get_user(userid) or AnonymousUser()
A userid w/ value of None causes the problem, according to the trackback.
What version of MongoEngine / Django are you using?
Have you enabled the django.contrib.auth.middleware.AuthenticationMiddleware? That should set a User instance or AnonymousUser to the request.
What does rs.claimutil.auth_backend.ClaimAuthBackend look like? And what does its get_user method return? Does it stop erroring if you just have one authentication backend?
In one of my views I had the following:
r_v.obj.backend = 'mongoengine.django.auth.MongoEngineBackend', which is why Django was ignoring the AUTHENTICATION_BACKENDS in settings.py, and was never using my custom authentication backend.

Categories

Resources