[Django] #36345: manage.py shouldn't do template rendering in migration-related commands

11 views
Skip to first unread message

Django

unread,
Apr 22, 2025, 2:38:50 AM4/22/25
to django-...@googlegroups.com
#36345: manage.py shouldn't do template rendering in migration-related commands
-----------------------------------+--------------------------------------
Reporter: Christophe Pettus | Type: Bug
Status: new | Component: Migrations
Version: 5.2 | 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
-----------------------------------+--------------------------------------
It appears that `manage.py makemigrations` and `manage.py migrate` do some
kind of template rendering. This can cause problem in a particular
situation:

1. The template rendering path make calls to the ORM (for example, setting
a Jinja2 global variable), and,
2. That call to the ORM uses one of the models being migrated, and,
3. The migration is incompatible between the current state on disk and the
model class.

The result is that it attempts to do a query with the current state of the
model class, which fails, because the migration has not been applied yet
(stack trace on 5.2 attached).
--
Ticket URL: <https://code.djangoproject.com/ticket/36345>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 22, 2025, 2:38:59 AM4/22/25
to django-...@googlegroups.com
#36345: manage.py shouldn't do template rendering in migration-related commands
-----------------------------------+--------------------------------------
Reporter: Christophe Pettus | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 5.2
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
-----------------------------------+--------------------------------------
Changes (by Christophe Pettus):

* Attachment "migration issue stack trace.txt" added.

Django

unread,
Apr 22, 2025, 2:39:23 AM4/22/25
to django-...@googlegroups.com
#36345: manage.py shouldn't do template rendering in migration-related commands
-----------------------------------+--------------------------------------
Reporter: Christophe Pettus | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 5.2
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
-----------------------------------+--------------------------------------
Changes (by Christophe Pettus):

* Attachment "migration issue stack trace.2.txt" added.

Stack trace on manage.py makemigrations

Django

unread,
Apr 22, 2025, 2:39:41 AM4/22/25
to django-...@googlegroups.com
#36345: manage.py shouldn't do template rendering in migration-related commands
-----------------------------------+--------------------------------------
Reporter: Christophe Pettus | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 5.2
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
-----------------------------------+--------------------------------------
Changes (by Christophe Pettus):

* Attachment "migration issue stack trace.2.txt" removed.

Django

unread,
Apr 22, 2025, 4:17:27 AM4/22/25
to django-...@googlegroups.com
#36345: manage.py shouldn't do template rendering in migration-related commands
-----------------------------------+--------------------------------------
Reporter: Christophe Pettus | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by David Sanders):

* resolution: => invalid
* status: new => closed

Comment:

Hey Christophe, glad to see you're still using Django!

We have a situation here where the system checks is being caught up with
some DB access. The contrib.admin system check is verifying dependencies
which in turn runs code from pgx-website/pgx/utils/jinja2.py which does
the DB access.

You can disable the system checks with `./manage.py makemigrations --skip-
checks`

It looks like this is project specific so I'll resolve this as invalid –
but if you feel this is a mistake please feel free to respond or even
start a thread on the Django forum 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/36345#comment:1>

Django

unread,
Apr 22, 2025, 10:50:44 AM4/22/25
to django-...@googlegroups.com
#36345: manage.py shouldn't do template rendering in migration-related commands
-----------------------------------+--------------------------------------
Reporter: Christophe Pettus | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.2
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Comment (by Christophe Pettus):

Thank you for the prompt response! Yes, I agree it's a bit of an edge
case, and thanks for the workaround!
--
Ticket URL: <https://code.djangoproject.com/ticket/36345#comment:2>
Reply all
Reply to author
Forward
0 new messages