1. fiji
  2. django-3k
Issue #54 duplicate

Fail to get proper IntegrityError in modeltests.get_or_create

Johan Harjono
created an issue

{{{

!python

====================================================================== FAIL: Doctest: modeltests.get_or_create.models.test.API_TESTS


Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 2222, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for modeltests.get_or_create.models.test.API_TESTS File "/home/johan/workspace/fiji/build/tests/modeltests/get_or_create/models.py", line unknown line number, in API_TESTS


File "/home/johan/workspace/fiji/build/tests/modeltests/get_or_create/models.py", line ?, in modeltests.get_or_create.models.test.API_TESTS Failed example: try: p, created = Person.objects.get_or_create(first_name='Tom', last_name='Smith') except Exception as e: if isinstance(e, IntegrityError): print("Pass") else: print("Fail with %s" % type(e)) Expected: Pass Got: Fail with <class 'TypeError'>


File "/home/johan/workspace/fiji/build/tests/modeltests/get_or_create/models.py", line ?, in modeltests.get_or_create.models.test.API_TESTS Failed example: try: m, created = ManualPrimaryKeyTest.objects.get_or_create(id=1, data='Different') except Exception as e: if isinstance(e, IntegrityError): print("Pass") else: print("Fail with %s" % type(e)) Expected: Pass Got: Fail with <class 'TypeError'>


Ran 1 test in 0.032s

FAILED (failures=1)

}}}

Comments (3)

  1. Dave Weber
    • changed status to open

    From the Django source code, an IntegrityError is an 'Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc. '

    From Python 2 documentation, TypeError is 'Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.' This is unchanged in Python 3.

  2. Log in to comment