Django TemplateSyntaxError: current transaction is aborting, what does this exception mean? Is postgresql 8.4 different from django?

Full error text:

TemplateSyntaxError on /

Showing an exception during rendering: the current transaction is aborted, commands are ignored until the end of the transaction block

I recently reinstalled all the software on my computer. The code didn't work before. It also still does not work on another computer and on the development server.

The only thing I can think of is probably the version of the postgresql server (and I'm not really sure if I tried to run it on 8.4 on my old installation or not - it definitely worked on 8.3). Can anyone confirm that Django has problems with postgresql 8.4 and / or has any hints as to why I have such errors?

Change 1

In response to Dominica ... This happens not only on one page or with one tag (although there are several pages that look fine). The only thing tags and variables that cause errors are that they accidentally access the database along the way (although not all tags that access the database cause an error). In addition, the same code does not throw a TemplateSyntaxError on other computers.

If I delete a variable or custom template tag that makes an error, then this is the chain of events that occur:

  • I am deleting a variable or tag that supposedly causes an error and refreshes the page.
  • Django selects another variable or tag and the same error occurs, so I keep deleting them.
  • After deleting all the variables and tags that cause the error, I stop getting the correct error page. I get a simple white page with the following trace:
  Traceback (most recent call last):

   File "/usr/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 279, in run
     self.result = application (self.environ, self.start_response)

   File "/usr/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 651, in __call__
     return self.application (environ, start_response)

   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 245, in __call__
     response = middleware_method (request, response)

   File "/usr/lib/python2.6/site-packages/debug_toolbar/middleware.py", line 90, in process_response
     response.content = replace_insensitive (smart_unicode (response.content), u '', smart_unicode (self.debug_toolbars [request] .render_toolbar () + u ''))

   File "/usr/lib/python2.6/site-packages/debug_toolbar/toolbar/loader.py", line 72, in render_toolbar
     'BASE_URL': self.request.META.get ('SCRIPT_NAME', ''),

   File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 108, in render_to_string
     return t.render (context_instance)

   File "/usr/lib/python2.6/site-packages/django/test/utils.py", line 29, in instrumented_test_render
     return self.nodelist.render (context)

   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 779, in render
     bits.append (self.render_node (node, context))

   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 71, in render_node
     result = node.render (context)

   File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 155, in render
     nodelist.append (node.render (context))

   File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 243, in render
     return self.nodelist_true.render (context)

   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 779, in render
     bits.append (self.render_node (node, context))

   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 81, in render_node
     raise wrapped

 TemplateSyntaxError: Caught an exception while rendering: current transaction is aborted, commands ignored until end of transaction block


 Original Traceback (most recent call last):
   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 71, in render_node
     result = node.render (context)
   File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 87, in render
     output = force_unicode (self.filter_expression.resolve (context))
   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 546, in resolve
     obj = self.var.resolve (context)
   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 687, in resolve
     value = self._resolve_lookup (context)
   File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 722, in _resolve_lookup
     current = current ()
   File "/usr/lib/python2.6/site-packages/debug_toolbar/panels/template.py", line 64, in content
     pformat (k (self.request))) for k in get_standard_processors ()
   File "/usr/lib/python2.6/site-packages/django/core/context_processors.py", line 27, in auth
     'messages': user.get_and_delete_messages (),
   File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 263, in get_and_delete_messages
     for m in self.message_set.all ():
   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 106, in _result_iter
     self._fill_cache ()
   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 692, in _fill_cache
     self._result_cache.append (self._iter.next ())
   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 238, in iterator
     for row in self.query.results_iter ():
   File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 287, in results_iter
     for rows in self.execute_sql (MULTI):
   File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql
     cursor.execute (sql, params)
   File "/usr/lib/python2.6/site-packages/debug_toolbar/panels/sql.py", line 91, in execute
     return self.cursor.execute (sql, params)
 InternalError: current transaction is aborted, commands ignored until end of transaction block 
+7
python django postgresql
source share
2 answers

This exception means that an error has occurred in some SQL that is running. Because Django runs all of the SQL inside the database transaction, all of the SQL that runs after the error is ignored. So:

BEGIN; SELECT * FROM table; SELECT missing_column FROM table WHERE id = 1; -- generates an error because the column is missing SELECT * FROM another_table; -- this statement and all following statements get ignored until the next COMMIT; COMMIT; 

To find out the problem, find the log file for PostgreSQL and run tail -f /path/to/postgresql_error.log . Then refresh the page. You should see an error appearing in the log file.

+13
source share

If you are moving from a different database, note that there may be some considerations to keep in mind that Django with Postgres uses transactions. Read here:

http://docs.djangoproject.com/en/dev/topics/db/transactions/?from=olddocs#handling-exceptions-within-postgresql-transactions

The quick answer, as a rule, is to enable auto-creation of the database level by adding:

 'OPTIONS': {'autocommit': True,} 

in the database settings. But you should read it and understand coo.

Rolo.

+4
source share

All Articles