#36345 closed Bug (invalid)
manage.py shouldn't do template rendering in migration-related commands
Reported by: | Christophe Pettus | Owned by: | |
---|---|---|---|
Component: | Migrations | Version: | 5.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It appears that manage.py makemigrations
and manage.py migrate
do some kind of template rendering. This can cause problem in a particular situation:
- The template rendering path make calls to the ORM (for example, setting a Jinja2 global variable), and,
- That call to the ORM uses one of the models being migrated, and,
- 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).
Attachments (1)
Change History (3)
by , 5 months ago
Attachment: | migration issue stack trace.txt added |
---|
comment:1 by , 5 months ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 5 months ago
Thank you for the prompt response! Yes, I agree it's a bit of an edge case, and thanks for the workaround!
Note:
See TracTickets
for help on using tickets.
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 👍