[Django] #36313: even with `reset_sequences=True` a class does not reset them on teardown

16 views
Skip to first unread message

Django

unread,
Apr 9, 2025, 3:18:47 PM4/9/25
to django-...@googlegroups.com
#36313: even with `reset_sequences=True` a class does not reset them on teardown
---------------------------------+-----------------------------------------
Reporter: anthony sottile | Type: Uncategorized
Status: new | Component: Uncategorized
Version: dev | 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
---------------------------------+-----------------------------------------
I have a particular test class which I know breaks primary key ordering
for a bunch of other tests in the process. I figured I could extend
`TransactionTestCase` and set `reset_sequences = True` on this class but
the sequence state persists after the test

seems this was improved in https://code.djangoproject.com/ticket/18271

I believe this minimal patch would fix it :

{{{
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 8f9ba977a3..e2cf63b56d 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1239,7 +1239,7 @@ class TransactionTestCase(SimpleTestCase):
verbosity=0,
interactive=False,
database=db_name,
- reset_sequences=False,
+ reset_sequences=cls.reset_sequences,
allow_cascade=self.available_apps is not None,
inhibit_post_migrate=inhibit_post_migrate,
)
}}}

I'm specifically using django 5.1.7 but given the code this also affects
the in-development version
--
Ticket URL: <https://code.djangoproject.com/ticket/36313>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 9, 2025, 3:26:20 PM4/9/25
to django-...@googlegroups.com
#36313: even with `reset_sequences=True` a class does not reset them on teardown
---------------------------------+--------------------------------------
Reporter: anthony sottile | Owner: (none)
Type: Uncategorized | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by anthony sottile:

Old description:

> I have a particular test class which I know breaks primary key ordering
> for a bunch of other tests in the process. I figured I could extend
> `TransactionTestCase` and set `reset_sequences = True` on this class but
> the sequence state persists after the test
>
> seems this was improved in https://code.djangoproject.com/ticket/18271
>
> I believe this minimal patch would fix it :
>
> {{{
> diff --git a/django/test/testcases.py b/django/test/testcases.py
> index 8f9ba977a3..e2cf63b56d 100644
> --- a/django/test/testcases.py
> +++ b/django/test/testcases.py
> @@ -1239,7 +1239,7 @@ class TransactionTestCase(SimpleTestCase):
> verbosity=0,
> interactive=False,
> database=db_name,
> - reset_sequences=False,
> + reset_sequences=cls.reset_sequences,
> allow_cascade=self.available_apps is not None,
> inhibit_post_migrate=inhibit_post_migrate,
> )
> }}}
>
> I'm specifically using django 5.1.7 but given the code this also affects
> the in-development version

New description:

I have a particular test class which I know breaks primary key ordering
for a bunch of other tests in the process. I figured I could extend
`TransactionTestCase` and set `reset_sequences = True` on this class but
the sequence state persists after the test

seems this was improved in https://code.djangoproject.com/ticket/18271

I believe this minimal patch would fix it :

{{{
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 8f9ba977a3..e2cf63b56d 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1239,7 +1239,7 @@ class TransactionTestCase(SimpleTestCase):
verbosity=0,
interactive=False,
database=db_name,
- reset_sequences=False,
+ reset_sequences=self.reset_sequences,
allow_cascade=self.available_apps is not None,
inhibit_post_migrate=inhibit_post_migrate,
)
}}}

I'm specifically using django 5.1.7 but given the code this also affects
the in-development version

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36313#comment:1>

Django

unread,
Apr 10, 2025, 12:16:27 PM4/10/25
to django-...@googlegroups.com
#36313: even with `reset_sequences=True` a class does not reset them on teardown
-----------------------------------+--------------------------------------
Reporter: anthony sottile | Owner: (none)
Type: Bug | Status: closed
Component: Testing framework | Version: dev
Severity: Normal | Resolution: needsinfo
Keywords: reset_sequences | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Natalia Bidart):

* cc: Jacob Walls (added)
* component: Uncategorized => Testing framework
* keywords: => reset_sequences
* resolution: => needsinfo
* status: new => closed
* type: Uncategorized => Bug

Comment:

Hello anthony sottile, thank you for taking the time to create this
report. We can't provide a solution from a diff, would need really need
either or both:
1. A test case for the Django source code that exercises the issue, and/or
2. A Django sample project with minimal logic and clear instructions to
reproduce this.

I'll be closing this ticket as `needsinfo`, but please reopen when you can
provide precise details on how to reproduce locally.
--
Ticket URL: <https://code.djangoproject.com/ticket/36313#comment:2>

Django

unread,
Apr 26, 2025, 5:27:16 AM4/26/25
to django-...@googlegroups.com
#36313: even with `reset_sequences=True` a class does not reset them on teardown
-----------------------------------+--------------------------------------
Reporter: anthony sottile | Owner: (none)
Type: Bug | Status: closed
Component: Testing framework | Version: dev
Severity: Normal | Resolution: worksforme
Keywords: reset_sequences | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Jacob Walls):

* resolution: needsinfo => worksforme

Comment:

Thanks for the CC.

The `reset_sequence` attribute is
[https://docs.djangoproject.com/en/5.1/topics/testing/advanced/#django.test.TransactionTestCase.reset_sequences
doc'd] to affect test setup, not teardown, on the idea that test cases
that are sensitive to primary key ordering should be opting in to the
reset overhead by setting `reset_sequences=True`. So under the current
paradigm, the sequence state persisting after the test is expected.

Changing this, I think, would require an impact analysis (DEP-lite?) on
test case ordering and any usability or performance upsides from changing
the behavior you called out.
--
Ticket URL: <https://code.djangoproject.com/ticket/36313#comment:3>
Reply all
Reply to author
Forward
0 new messages