class CustomManagerThatFillterOutSomeRecords(Manager):
def get_queryset(self):
return super().get_queryset().exclude(pk=1)
}}}
tests.py
{{{
class TestService(TransactionTestCase):
serialized_rollback = True
def test_something(self):
pass
}}}
Assume we have a migration that creates few records of Service.
{{{
from django.core.management import call_command
from django.db import migrations
def load_fixtures(*_, **__):
call_command('loaddata', 'services.json')
class Migration(migrations.Migration):
dependencies = []
operations = [
migrations.RunPython(
load_fixtures,
migrations.RunPython.noop,
)
]
}}}
Then `TestService` will fail as `serialize_db_to_string` by default use
`_default_manager` that is `CustomManagerThatFillterOutSomeRecords`.
Here is proposed fix: https://github.com/django/django/pull/13150
--
Ticket URL: <https://code.djangoproject.com/ticket/31762>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Bug
* has_patch: 0 => 1
* component: Uncategorized => Testing framework
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted
Comment:
That makes sense.
You'll need to add regression tests to your PR in
[django/db/backends/base/creation.py
https://github.com/django/django/blob/4d9cd89acbb944e10b9000092069ba8e3a855957/django/db/backends/base/creation.py]
by defining a default manager that exclude rows
`django/db/backends/models.py`, creating one such row, and ensure it's
part of the string returned by `serialize_db_to_string`.
--
Ticket URL: <https://code.djangoproject.com/ticket/31762#comment:1>
* owner: nobody => Hasan Ramezani
* status: new => assigned
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/31762#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31762#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"50c3ac6fa9b7c8a94a6d1dc87edf775e3bc4d575" 50c3ac6]:
{{{
#!CommitTicketReference repository=""
revision="50c3ac6fa9b7c8a94a6d1dc87edf775e3bc4d575"
Fixed #31762 -- Made reloading the database for tests use the base
manager.
Co-authored-by: Eugene Kulak <kulak....@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31762#comment:4>