Opened 14 years ago
Closed 13 years ago
#15076 closed Bug (fixed)
inspectdb to quote ForeignKey class names to avoid need to reorder classes/solve circular dependencies
Reported by: | saschwarz | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.2 |
Severity: | Normal | Keywords: | inspectdb |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The inspectdb management command supplies either "self" or the unquoted name of foreign key's class as the first argument to the ForeignKey constructor. This requires that classes be defined prior to their first use. If the class name were supplied as a quoted string the ordering of classes isn't required. That would also solve the case where circular dependencies keep classes from being defined in an appropriate order.
I've attached the trivial changes as a diff from trunk 15194.
Attachments (3)
Change History (15)
by , 14 years ago
Attachment: | inspectdb_15194.diff added |
---|
comment:1 by , 14 years ago
Component: | Uncategorized → ORM aggregation |
---|---|
Owner: | removed |
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 14 years ago
Component: | ORM aggregation → django-admin.py inspectdb |
---|---|
Owner: | set to |
by , 14 years ago
Attachment: | django-fk-quoting.diff added |
---|
Quote ForeignKey models only if the model has not appeared yet.
comment:3 by , 14 years ago
Please see attached patch; it only quotes model names if the model has not yet been written out. Is that an acceptable deal? It should prevent quoting known model names but still quote model names that have not been initialized yet.
comment:4 by , 14 years ago
Component: | django-admin.py inspectdb → Core (Management commands) |
---|
comment:5 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:6 by , 13 years ago
Easy pickings: | unset |
---|---|
UI/UX: | unset |
#16476 was a duplicate. And yes, it sounds like a good idea.
comment:7 by , 13 years ago
Keywords: | inspectdb added |
---|
comment:8 by , 13 years ago
Needs tests: | set |
---|
comment:10 by , 13 years ago
Has patch: | set |
---|---|
Needs tests: | unset |
comment:11 by , 13 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
If I remember correctly, specifying the FK destination model name inside quotes doesn't work well when the model is already known, so a general solution like this (always using quoting) can result in faulty introspected models.py's.