pytest-dev / pytest-dev/pytest-django
When running pytest on a database with --reuse-db where python manage.py migrate was already run, cause failure on old runpython
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
I explain myself,
I have a project with a lot of migrations, with 3 important migrations for our case (in that order):
- a migration that add the field
footo the modelBar - a migration that has a RunPython, doing some computation based on the field foo
- a migration that remove the field
foo
now if i first do
python manage.py migrate
I finish with a database without field foo => normal and expected
if I then run pytest --reuse-db I will got SQL failure because pytest re-runs all migrations, but without actually replaying the changes on the database , but only running the RunPython, so the RunPython of 2) is run on database were the field has already been removed
is it a known behaviour , if so why ?
I would have thought that it would see migrations has been run , and will not execute anything, runpython included
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the sequence with python manage.py migrate followed by pytest --reuse-db, focusing on the migrations containing RunPython and the removed foo field. Trace how pytest-django determines which migrations to apply and verify whether the database state is expected; done means the behavior is explained or corrected with a regression test for this sequence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend, databases, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100