#22487: Moving from initial_data to data migrations stops test data persisting
-------------------------------------+-------------------------------------
Reporter: andrewgodwin | Owner:
Type: Bug | andrewgodwin
Component: Testing framework | Status: closed
Severity: Release blocker | Version:
Keywords: | 1.7-beta-1
Has patch: 0 | Resolution: fixed
Needs tests: 0 | Triage Stage: Accepted
Easy pickings: 0 | Needs documentation: 0
| Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by RafalP):
Hello Andrew,
I've removed all test cases from my test suite, leaving only one. It's
{{{TransactionTestCase}}} with {{{serialized_rollback = True}}}, and now I
have errors on table repopulation:
{{{
======================================================================
ERROR: test_invalid_name
(misago.users.tests.test_validators.ValidateUsernameLengthTests)
validate_username_length disallows invalid names
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/test/testcases.py", line 182, in __call__
self._pre_setup()
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/test/testcases.py", line 754, in _pre_setup
self._fixture_setup()
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/test/testcases.py", line 797, in _fixture_setup
connections[db_name]._test_serialized_contents
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/backends/creation.py", line 435, in
deserialize_db_from_string
obj.save()
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/core/serializers/base.py", line 176, in save
setattr(self.object, accessor_name, object_list)
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/models/fields/related.py", line 1177, in __set__
manager.add(*value)
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/models/fields/related.py", line 917, in add
self._add_items(self.source_field_name, self.target_field_name, *objs)
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/models/fields/related.py", line 1026, in _add_items
for obj_id in new_ids
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/models/query.py", line 407, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/transaction.py", line 339, in __exit__
connection.commit()
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/backends/__init__.py", line 176, in commit
self._commit()
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/backends/__init__.py", line 145, in _commit
return self.connection.commit()
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/rafapiton/venvs/misago06/lib/python2.7/site-
packages/django/db/backends/__init__.py", line 145, in _commit
return self.connection.commit()
IntegrityError: insert or update on table "misago_users_rank_roles"
violates foreign key constraint
"misago_users_ran_role_id_5cb6d82bf6031b71_fk_misago_acl_role_id"
DETAIL: Key (role_id)=(3) is not present in table "misago_acl_role".
}}}
Also please correct me if I am wrong, but from reading documentation I get
picture that if my app contains data migrations, and this data is
important for my tests, I should make those tests inherit from
{{{TestCase}}} and use database with transactions support (such as
Postgres)?
Thanks for your time,
Ralph
--
Ticket URL: <https://code.djangoproject.com/ticket/22487#comment:22>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.507bd18c7df1faa64305d9f74b9f17ea%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.