Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#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:

  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).

Attachments (1)

migration issue stack trace.txt (6.7 KB ) - added by Christophe Pettus 5 months ago.

Download all attachments as: .zip

Change History (3)

by Christophe Pettus, 5 months ago

comment:1 by David Sanders, 5 months ago

Resolution: invalid
Status: newclosed

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 👍

comment:2 by Christophe Pettus, 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.
Back to Top