Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1346 closed defect (fixed)

django-admin creates invalid m2m table if the related models have same primary key name

Reported by: Russell Keith-Magee Owned by: Russell Keith-Magee
Component: Core (Management commands) Version: magic-removal
Severity: normal Keywords: recursive m2m primary key
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the following model

class Article(models.Model):
    ...
    related = models.ManyToManyField("Article")

This model currently breaks magic-removal - the SQL created on install is invalid, because the m2m table for the many-to-many field has two columns named article_id. This is easy to cause if you recursively define a m2m relationship; you can probably get a similar problem if you use custom primary key names.

At the very least, this should be picked up as a validation error; ideally, we need a strategy for producing unique column names in the m2m table.

Change History (5)

comment:1 by Russell Keith-Magee, 19 years ago

(In [2380]) magic-removal: Refs #1346 -- Added unit tests for expected behaviour of self referential m2m fields.

comment:2 by Russell Keith-Magee, 19 years ago

(In [2381]) magic-removal: Refs #1346 -- Refactored query logic for m2m descriptor fields, and added logic to m2m name methods to allow m2m_recursive tests to create a valid SQL table.

comment:3 by Russell Keith-Magee, 19 years ago

(In [2382]) magic-removal: Refs #1346 -- Added the production of 'mirror' entries in the m2m table for m2m relations to self.

comment:4 by Russell Keith-Magee, 19 years ago

Resolution: fixed
Status: newclosed

(In [2383]) magic-removal: Fixes #1346 -- Added ability for m2m relations to self to be optionally non-symmetrical. Added unit tests for non-symmetrical behaviour.

comment:5 by Russell Keith-Magee, 19 years ago

(In [2384]) magic-removal: Refs #1346 -- Removed some redundant code that was missed in the checkin for r2381.

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