#34985: Migrations raise AppRegistryNotReady when GeneratedField references incorrect fields. -------------------------------------+------------------------------------- Reporter: Paolo Melchiorre | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 5.0 (models, ORM) | Severity: Release blocker | Resolution: Keywords: field, database, | Triage Stage: Accepted generated, output_field | Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by Mariusz Felisiak):
* cc: Lily Foote (added) * severity: Normal => Release blocker * stage: Unreviewed => Accepted Comment: Thanks for the report. We could add a small check for `GeneratedField` references, e.g. {{{#!diff diff --git a/django/db/models/base.py b/django/db/models/base.py index 64d54380da..62ce34c4f8 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1601,6 +1601,7 @@ class Model(AltersData, metaclass=ModelBase): *cls._check_constraints(databases), *cls._check_default_pk(), *cls._check_db_table_comment(databases), + *cls._check_generated_fields(databases), ] return errors @@ -1957,6 +1958,18 @@ class Model(AltersData, metaclass=ModelBase): errors.extend(cls._check_local_fields(fields, "unique_together")) return errors + @classmethod + def _check_generated_fields(cls, databases): + errors = [] + for f in cls._meta.local_fields: + if not f.generated: + continue + references = { + ref[0] for ref in cls._get_expr_references(f.expression) + } + errors.extend(cls._check_local_fields(references, f.name)) + return errors + @classmethod def _check_indexes(cls, databases): """Check fields, names, and conditions of indexes.""" }}} Unfortunately, this would still required catching exceptions when resolving `GeneratedField` expressions. -- Ticket URL: <https://code.djangoproject.com/ticket/34985#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018bf566bbaa-24d0984b-7202-4871-b5a4-9f0b37053893-000000%40eu-central-1.amazonses.com.