Opened 13 years ago

Closed 12 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)

inspectdb_15194.diff (833 bytes ) - added by saschwarz 13 years ago.
django-fk-quoting.diff (1.3 KB ) - added by jeff@… 13 years ago.
Quote ForeignKey models only if the model has not appeared yet.
15194-3.diff (2.3 KB ) - added by Claude Paroz 12 years ago.
Identical patch + updated test

Download all attachments as: .zip

Change History (15)

by saschwarz, 13 years ago

Attachment: inspectdb_15194.diff added

comment:1 by Ramiro Morales, 13 years ago

Component: UncategorizedORM aggregation
Owner: nobody removed
Triage Stage: UnreviewedDesign decision needed

If I remember correctly, specifying the FK destination model name inside quotes doesn't work well when the model is already known, so a wholesale solution like this (always using quoting) can result in faulty introspected models.py's.

Last edited 12 years ago by Ramiro Morales (previous) (diff)

comment:2 by Ramiro Morales, 13 years ago

Component: ORM aggregationdjango-admin.py inspectdb
Owner: set to nobody

by jeff@…, 13 years ago

Attachment: django-fk-quoting.diff added

Quote ForeignKey models only if the model has not appeared yet.

comment:3 by jeff@…, 13 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 Gabriel Hurley, 13 years ago

Component: django-admin.py inspectdbCore (Management commands)

comment:5 by James Addison, 13 years ago

Severity: Normal
Type: Bug

comment:6 by Aymeric Augustin, 13 years ago

Easy pickings: unset
UI/UX: unset

#16476 was a duplicate. And yes, it sounds like a good idea.

comment:7 by Ramiro Morales, 13 years ago

Keywords: inspectdb added

comment:8 by Ramiro Morales, 12 years ago

Needs tests: set

comment:9 by Ramiro Morales, 12 years ago

Triage Stage: Design decision neededAccepted

#9164 was a duplicate.

by Claude Paroz, 12 years ago

Attachment: 15194-3.diff added

Identical patch + updated test

comment:10 by Claude Paroz, 12 years ago

Has patch: set
Needs tests: unset

comment:11 by Ramiro Morales, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:12 by Claude Paroz, 12 years ago

Resolution: fixed
Status: newclosed

In [17942]:

Fixed #15076 -- Quoted ForeignKey target class names in inspectdb when class is defined below.

Thanks saschwarz for the report, jeff@… for the initial patch and Ramiro Morales for the review.

Note: See TracTickets for help on using tickets.
Back to Top