Opened 10 years ago

Closed 10 years ago

#23110 closed Bug (needsinfo)

TransactionManagementError when exception is thrown in django/contrib/sessions/backends/cached_db.py

Reported by: karthikr Owned by: nobody
Component: Core (Cache system) Version: 1.6
Severity: Normal Keywords:
Cc: karthikr12 Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I was in the process of upgrading from django 1.5.1 to 1.6.5, and found this wierd issue. When I try to access any block of code which accesses the request.user object, the transaction.commit() fails because of the session. (Session matching query does not exist)

Environment:


Request Method: GET
Request URL: http://dev.wnyc.net:9876/in_iframe/accounts/login/

Django Version: 1.6.5
Python Version: 2.7.3


Traceback:
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  137.                 response = response.render()
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/template/response.py" in render
  105.             self.content = self.rendered_content
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  82.         content = template.render(context)
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/settings/monkeypatch.py" in render
  67.             return self.template_obj.render_unicode(**context_to_dict(context))
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/mako/template.py" in render_unicode
  198.                                 as_unicode=True)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/mako/runtime.py" in _render
  403.     _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/mako/runtime.py" in _render_context
  434.         _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/mako/runtime.py" in _exec_template
  457.         callable_(context, *args, **kwargs)
File "/tmp/kravindra/makopuppy/puppysite/base/really_stripped.html.py" in render_body
  88.         __M_writer(unicode(self.body()))
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/mako/runtime.py" in <lambda>
  278.             return lambda *args, **kwargs:callable_(self.context, *args, **kwargs)
File "/tmp/kravindra/makopuppy/puppysite/registration/login.html.py" in render_body
  72.             runtime._include_file(context, u'/registration/socialregistration.html', _template_uri)
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/mako/runtime.py" in _include_file
  341.     callable_(ctx, **_kwargs_for_include(callable_, context._orig, **kwargs))
File "/tmp/kravindra/makopuppy/puppysite/registration/socialregistration.html.py" in render_body
  66.             __M_writer(unicode(django_template_tag(request, template_tag_function, template_path)))
File "/home/kravindra/workspace/puppysite/puppy/util/templateutils.py" in django_template_tag
  30.         tag_context = Context(dict_=template_tag_function(context_getting_context))
File "/usr/local/virtualenvs/karthik-django165/local/lib/python2.7/site-packages/socialregistration/templatetags/facebook_tags.py" in facebook_button
  15.     logged_in = context['request'].user.is_authenticated()
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 /in_iframe/accounts/login/
Exception Value: This is forbidden when an 'atomic' block is active.

I am using cached_db as the session engine

SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'

Should I change this to

SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

the outcome is the same.

Some more context:

Backend database - POSTGRES

Have included the middleware classes, etc as recommended in the django 1.6 documentation.

Lets say I inject a dummy 'session', everything works fine.

Has anyone else seen this issue? I went through StackOverflow, and the tickets in in code.djangoproject.com, and none of them seem to address this specific issue.

Change History (2)

comment:1 by karthikr12, 10 years ago

Cc: karthikr12 added

comment:2 by Tim Graham, 10 years ago

Resolution: needsinfo
Status: newclosed

We'd need a minimal project to reproduce the issue or a test for Django's test suite in order to investigate, but I'd say it's more likely that this is a bug somewhere in your own project and not in Django in which case please see TicketClosingReasons/UseSupportChannels.

Please reopen if you can provide more details that suggests this is a bug in Django itself. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top