You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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: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 inconftest.py
(I'm usingpy.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:
I'm also running
pytest-django
with the the--reuse-db
flag, so migrations are not re-run, includingMyType.Operation()
.As I mentioned this can very well be the result of my test configuration, but any help or guidance would be appreciated.
The text was updated successfully, but these errors were encountered: