[Django] #31762: Dabase creation backend should use base_manager to serialize database

6 views
Skip to first unread message

Django

unread,
Jul 4, 2020, 3:44:41 PM7/4/20
to django-...@googlegroups.com
#31762: Dabase creation backend should use base_manager to serialize database
-----------------------------------------+------------------------
Reporter: Eugene K | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
models.py
{{{
class Service(Model):
objects = CustomManagerThatFillterOutSomeRecords()

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.

Django

unread,
Jul 4, 2020, 3:56:40 PM7/4/20
to django-...@googlegroups.com
#31762: Dabase creation backend should use base_manager to serialize database
-----------------------------------+------------------------------------

Reporter: Eugene K | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Simon Charette):

* 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>

Django

unread,
Nov 10, 2020, 5:48:39 PM11/10/20
to django-...@googlegroups.com
#31762: Dabase creation backend should use base_manager to serialize database
-------------------------------------+-------------------------------------
Reporter: Eugene K | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31762#comment:2>

Django

unread,
Nov 11, 2020, 2:34:32 AM11/11/20
to django-...@googlegroups.com
#31762: Dabase creation backend should use base_manager to serialize database
-------------------------------------+-------------------------------------
Reporter: Eugene K | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Testing framework | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31762#comment:3>

Django

unread,
Nov 11, 2020, 3:16:07 AM11/11/20
to django-...@googlegroups.com
#31762: Dabase creation backend should use base_manager to serialize database
-------------------------------------+-------------------------------------
Reporter: Eugene K | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Testing framework | Version: 3.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages