django-postgres-composite-types icon indicating copy to clipboard operation
django-postgres-composite-types copied to clipboard

Typecaster configuration lost across pytest-django test runs

Open dalberto opened this issue 7 years ago • 1 comments

When running a test suite in a project that uses django-postgres-composite-types I observed some unexpected behavior. The test suite succeeded on the first run (as expected). However, when re-running the test suite, tests that exercised models that have composite types, failed with an error like:

AttributeError: 'str' object has no attribute 'my_field'

After further inspection, I found that the types were not correctly cast in subsequent runs (even though they were always correctly persisted). In subsequent runs, the type for the composite type field was indeed str, while during the first run it was the correct type.

My workaround is to simply call the type's register_composite method at the very beginning of the test run in conftest.py (I'm using py.test).

This issue does not manifest itself when running Django's development server or when running Django with gunicorn, so it can very well have something to do with how the test suite is configured.

For reference, I'm running:

django 1.11.3
psycopg2 2.7.3
pytest 3.1.3
pytest-django 3.1.2

I'm also running pytest-django with the the --reuse-db flag, so migrations are not re-run, including MyType.Operation().

As I mentioned this can very well be the result of my test configuration, but any help or guidance would be appreciated.

dalberto avatar Jul 31 '17 18:07 dalberto

I've not used pytest-django, so I don't know how it initialises the database. Can you reduce it down to a test case?

danni avatar Aug 01 '17 05:08 danni