Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use run_syncdb in reset #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

use run_syncdb in reset #263

wants to merge 1 commit into from

Conversation

xi
Copy link

@xi xi commented Jan 17, 2022

In my project I have two databases. When testing a migration I got the following error:

Database queries to 'secondary' are not allowed in this test. Add 'secondary' to pytest_django.fixtures._django_db_helper.<locals>.PytestDjangoTestCase.databases to ensure proper test isolation and silence this failure.

This was odd because the test did not use the secondary database at all. By inspecting the stack trace I found that migrator.reset() executes all migrations, and there is actually an unrelated migration that uses the secondary database.

I think migrator.reset() should not execute all migrations. Therefore it seems like a good idea to use the --run-syncdb option. (I am not perfectly sure whether I got the syntax right)

@sobolevn
Copy link
Member

@xi can you please think of any simple test cases to reproduce this? 🤔

@xi
Copy link
Author

xi commented Jan 17, 2022

I am having trouble with the test case. I was trying to add a new migration that fails for some reason and then verify that this migration is not executed when calling migrator.reset(). I was not sure how to do that without breaking a lot of other tests though. My second attempt was to patch django.db.migrations.RunPython but that I realized that the migrations are executed by a separate interpreter so that my mock is not actually used. Do you have any ideas how to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants