id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 8739 Transaction problems with save(force_insert=True) on postgresql (and likely other transactional dbs) Richard Davies nobody "I attach a patch which adds an extra test, regressiontests/save_force_insert. This test succeeds with a SQLite backend, but fails with a postgreSQL backend. The postgreSQL error cites the line immediately after the call to save(force_insert=True), but I believe that this means that the transaction was aborted when save(force_insert=True) threw an exception, and that some form of savepoint protection may be needed inside the implementation of save(). {{{ $ ./runtests.py --settings=sqlite save_force_insert ---------------------------------------------------------------------- Ran 1 test in 0.005s OK $ ./runtests.py --settings=postgresql_psycopg2 save_force_insert ====================================================================== FAIL: Doctest: regressiontests.save_force_insert.models.__test__.API_TESTS ---------------------------------------------------------------------- Traceback (most recent call last): File ""/home/elastic/django-dev/trunk/django/test/_doctest.py"", line 2180, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for regressiontests.save_force_insert.models.__test__.API_TESTS File ""/home/elastic/django-dev/trunk/tests/regressiontests/save_force_insert/models.py"", line unknown line number, in API_TESTS ---------------------------------------------------------------------- File ""/home/elastic/django-dev/trunk/tests/regressiontests/save_force_insert/models.py"", line ?, in regressiontests.save_force_insert.models.__test__.API_TESTS Failed example: ManualPrimaryKeyTest.objects.get(id=1).data == 'Original' Exception raised: Traceback (most recent call last): File ""/home/elastic/django-dev/trunk/django/test/_doctest.py"", line 1267, in __run compileflags, 1) in test.globs File """", line 1, in ManualPrimaryKeyTest.objects.get(id=1).data == 'Original' File ""/home/elastic/django-dev/trunk/django/db/models/manager.py"", line 81, in get return self.get_query_set().get(*args, **kwargs) File ""/home/elastic/django-dev/trunk/django/db/models/query.py"", line 296, in get num = len(clone) File ""/home/elastic/django-dev/trunk/django/db/models/query.py"", line 152, in __len__ self._result_cache = list(self.iterator()) File ""/home/elastic/django-dev/trunk/django/db/models/query.py"", line 267, in iterator for row in self.query.results_iter(): File ""/home/elastic/django-dev/trunk/django/db/models/sql/query.py"", line 206, in results_iter for rows in self.execute_sql(MULTI): File ""/home/elastic/django-dev/trunk/django/db/models/sql/query.py"", line 1665, in execute_sql cursor.execute(sql, params) InternalError: current transaction is aborted, commands ignored until end of transaction block ---------------------------------------------------------------------- Ran 1 test in 0.012s FAILED (failures=1) }}}" closed Database layer (models, ORM) dev invalid richard.davies@… Unreviewed 0 0 0 0 0 0