#15802: Django stops functioning when the database (PostgreSQL) closes the
connection
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  Honza_Kral
  Rick.van.Hattem@…                  |         Status:  reopened
                   Type:  Bug        |      Component:  Database layer
              Milestone:             |  (models, ORM)
                Version:  1.3        |       Severity:  Normal
             Resolution:             |       Keywords:  database, postgres,
           Triage Stage:  Accepted   |  postgresql, connection, closed
    Needs documentation:  0          |      Has patch:  1
Patch needs improvement:  0          |    Needs tests:  0
                  UI/UX:  0          |  Easy pickings:  0
-------------------------------------+-------------------------------------
Changes (by dekkers):

 * status:  closed => reopened
 * cc: dekkers (added)
 * has_patch:  0 => 1
 * resolution:  fixed =>


Comment:

 I'm hitting the same problem, but when getting the cursor instead of
 closing the connection:

 {{{#!python
   File "/home/jener-www/jener/yatemod/backend.py", line 38, in
 get_account_hashes
     account = Account.objects.get(username=username, domain=domain)
   File "/usr/lib/python2.6/dist-packages/django/db/models/manager.py",
 line 131, in get
     return self.get_query_set().get(*args, **kwargs)
   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py", line
 338, in get
     num = len(clone)
   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py", line
 81, in __len__
     self._result_cache = list(self.iterator())
   File "/usr/lib/python2.6/dist-packages/django/db/models/query.py", line
 268, in iterator
     for row in compiler.results_iter():
   File "/usr/lib/python2.6/dist-
 packages/django/db/models/sql/compiler.py", line 701, in results_iter
     for rows in self.execute_sql(MULTI):
   File "/usr/lib/python2.6/dist-
 packages/django/db/models/sql/compiler.py", line 755, in execute_sql
     cursor = self.connection.cursor()
   File "/usr/lib/python2.6/dist-packages/django/db/backends/__init__.py",
 line 281, in cursor
     cursor = util.CursorWrapper(self._cursor(), self)
   File "/usr/lib/python2.6/dist-
 packages/django/db/backends/postgresql_psycopg2/base.py", line 173, in
 _cursor
     cursor = self.connection.cursor()
 InterfaceError: connection already closed
 }}}

 The problem is again that self.connection isn't None, but it isn't usable
 either, and we will loop over this error again and again. The attached
 patch will catch the exception and call close(), so that we can continue
 with creating a new connection.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/15802#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to