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 8740 save(force_update=True) should raise a consistent exception when update is not possible Richard Davies nobody "At present save(force_update=True) raises different exceptions according to database backend when update is not possible. These should be unified so that calling code is not specific to the database backend, rather like IntegrityError is already. They could be unified onto IntegrityError itself or a different new error. I attach a patch which adds an extra test, regressiontests/save_force_update. This test assumes that save(force_update=True) would raise IntegrityError. In the trace below you can see that different database backends actually each fail with different exceptions. {{{ $ ./runtests.py --settings=sqlite save_force_update ====================================================================== FAIL: Doctest: regressiontests.save_force_update.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_update.models.__test__.API_TESTS File ""/home/elastic/django-dev/trunk/tests/regressiontests/save_force_update/models.py"", line unknown line number, in API_TESTS ---------------------------------------------------------------------- File ""/home/elastic/django-dev/trunk/tests/regressiontests/save_force_update/models.py"", line ?, in regressiontests.save_force_update.models.__test__.API_TESTS Failed example: try: m = ManualPrimaryKeyTest(id=2, data='Different') m.save(force_update=True) except Exception, e: if isinstance(e, IntegrityError): print ""Pass"" else: print ""Fail with %s"" % type(e) Expected: Pass Got: Fail with ---------------------------------------------------------------------- Ran 1 test in 0.012s FAILED (failures=1) $ ./runtests.py --settings=postgresql_psycopg2 save_force_update ====================================================================== FAIL: Doctest: regressiontests.save_force_update.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_update.models.__test__.API_TESTS File ""/home/elastic/django-dev/trunk/tests/regressiontests/save_force_update/models.py"", line unknown line number, in API_TESTS ---------------------------------------------------------------------- File ""/home/elastic/django-dev/trunk/tests/regressiontests/save_force_update/models.py"", line ?, in regressiontests.save_force_update.models.__test__.API_TESTS Failed example: try: m = ManualPrimaryKeyTest(id=2, data='Different') m.save(force_update=True) except Exception, e: if isinstance(e, IntegrityError): print ""Pass"" else: print ""Fail with %s"" % type(e) Expected: Pass Got: Fail with ---------------------------------------------------------------------- Ran 1 test in 0.067s FAILED (failures=1) }}}" Bug closed Database layer (models, ORM) dev Normal invalid richard.davies@… Accepted 0 0 0 0 0 0