Opened 6 weeks ago

Last modified 6 weeks ago

#31762 new Bug

Dabase creation backend should use base_manager to serialize database

Reported by: Eugene K Owned by: nobody
Component: Testing framework Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


class Service(Model):
    objects = CustomManagerThatFillterOutSomeRecords()

class CustomManagerThatFillterOutSomeRecords(Manager):
    def get_queryset(self):
        return super().get_queryset().exclude(pk=1)

class TestService(TransactionTestCase):
    serialized_rollback = True

    def test_something(self):

Assume we have a migration that creates few records of Service.

from import call_command
from django.db import migrations

def load_fixtures(*_, **__):
    call_command('loaddata', 'services.json')

class Migration(migrations.Migration):
    dependencies = []

    operations = [

Then TestService will fail as serialize_db_to_string by default use _default_manager that is CustomManagerThatFillterOutSomeRecords.

Here is proposed fix:

Change History (1)

comment:1 Changed 6 weeks ago by Simon Charette

Component: UncategorizedTesting framework
Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

That makes sense.

You'll need to add regression tests to your PR in [django/db/backends/base/] by defining a default manager that exclude rows django/db/backends/, creating one such row, and ensure it's part of the string returned by serialize_db_to_string.

Note: See TracTickets for help on using tickets.
Back to Top