Tuesday, August 11, 2015

InterfaceError: connection already closed from psycopg2 when running Django Tests

I'm trying to implement testing on a fairly large Django site, and I'm encountering a psycopg2 error when running all the tests at once using `python manage.py test`. If I specify each app name individually, it works fine (some tests fail, but all for legitimate reasons), however when I run them all at once, it works as expected for the first 20-30 tests, and then I get a large number failing at once, all with an interface error.

    ======================================================================
        ERROR
: testFunctionality (proj.apps.myapp.tests.AppFunction)
       
----------------------------------------------------------------------
       
Traceback (most recent call last):
         
File "C:\projects\WidgetCo\src\django\widget\apps\app\tests.py", line 31, in setUp
            data
.createClients()
         
File "C:\projects\WidgetCo\src\django\testApp\data.py", line 61, in createClients
            createCompanies
()
         
File "C:\projects\WidgetCo\src\django\testApp\data.py", line 54, in createCompanies
            company1
.save()
         
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 710, in save
            force_update
=force_update, update_fields=update_fields)
         
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 738, in save_base
            updated
= self._save_table(raw, cls, force_insert, force_update, using, update_fields)
         
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 822, in _save_table
            result
= self._do_insert(cls._base_manager, using, fields, update_pk, raw)
         
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 861, in _do_insert
           
using=using, raw=raw)
         
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 127, in manager_method
           
return getattr(self.get_queryset(), name)(*args, **kwargs)
         
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 920, in _insert
           
return query.get_compiler(using=using).execute_sql(return_id)
         
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 972, in execute_sql
           
with self.connection.cursor() as cursor:
         
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 164, in cursor
            cursor
= self.make_cursor(self._cursor())
         
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 137, in _cursor
           
return self.create_cursor()
         
File "C:\Python27\lib\site-packages\django\db\utils.py", line 97, in __exit__
            six
.reraise(dj_exc_type, dj_exc_value, traceback)
         
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 137, in _cursor
           
return self.create_cursor()
         
File "C:\Python27\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 212, in create_cursor
            cursor
= self.connection.cursor()
       
InterfaceError: connection already closed


It looks like the postgresql database is closing mid-test, but I'm not sure why or how to stop it. I've tried setting a really high value for CONN_MAX_AGE as well as leaving it as default (never close). I've looked at the test where it starts to fail (it's always the same one) and nothing appears out of the ordinary. Any suggestions would be appreciated.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a8e52742-9e20-4854-b2ab-e972a7e54b1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment