[Django] #12386: Automatic ManyToMany Fields in models defined in packages use invalid column names

0 views
Skip to first unread message

Django

unread,
Dec 15, 2009, 7:52:29 PM12/15/09
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
-----------------------------+----------------------------------------------
Reporter: ldevesine | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: SVN
Keywords: | Stage: Unreviewed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
-----------------------------+----------------------------------------------
Using an M2M field in a model that is defined in a models package (that
is, in member.models.membership where member is an app and app_label is
defined as 'member' in the models) tries to access invalid column names to
retrieve data.

In member.models.membership I have defined a MembershipType with a
ManyToManyField subscriptions on SubscriptionType, defined in the same
file. When I attempt to access this M2M relationship, I get the error:
"Unknown column 'membership_type_subscriptions.member.subscriptiontype_id'
in 'field list'"

This bug appears only in the SVN version.

--
Ticket URL: <http://code.djangoproject.com/ticket/12386>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 17, 2009, 12:37:09 PM12/17/09
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
---------------------------------------------------+------------------------
Reporter: ldevesine | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by ldevesine):

* component: Uncategorized => Database layer (models, ORM)

--
Ticket URL: <http://code.djangoproject.com/ticket/12386#comment:1>

Django

unread,
Dec 17, 2009, 4:40:19 PM12/17/09
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
---------------------------------------------------+------------------------
Reporter: ldevesine | Owner: nobody
Status: new | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Comment (by ldevesine):

On further review, the problem is that I still had the old column name of
'subscriptiontype_id' in my database. Changing the column name to
'member.subscriptiontype_id' does resolve the problem, and syncdb creates
the column with the 'correct' name automatically. I am, however, not
certain that django should be creating tables with columns with '.'
characters in the name automatically...

--
Ticket URL: <http://code.djangoproject.com/ticket/12386#comment:2>

Django

unread,
Dec 19, 2009, 9:49:16 AM12/19/09
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
---------------------------------------------------+------------------------
Reporter: ldevesine | Owner: nobody
Status: closed | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Resolution: worksforme | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by ramiro):

* status: new => closed
* resolution: => worksforme

Comment:

I can't reproduce this. FInd attached an hypothetical
`model_package_regress` regression test that shows Django is generation
correct table and column names for the m2m field (tested with sqlite3
here) between two models defined in a `models` package.

I'm going to close this ticket. Reopen it you can modify the test case to
exactly reproduce your setup and you reproduce the error you report. If
so, include a patch or an exact copy of the code. Thanks.

--
Ticket URL: <http://code.djangoproject.com/ticket/12386#comment:3>

Django

unread,
Dec 21, 2009, 4:32:07 PM12/21/09
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
---------------------------------------------------+------------------------
Reporter: ldevesine | Owner: nobody
Status: reopened | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by ldevesine):

* status: closed => reopened
* resolution: worksforme =>

Comment:

Ah, the difference appears to be that I am defining the m2m relationship
using a string and specifying the app the 'to' model is in. I've attached
a very slightly altered version of your diff file that reproduces the same
issue for me. I suppose it's possible I'm just never supposed to define an
m2m relationship this way? If so, that should probably be documented
and/or throw an exception.

--
Ticket URL: <http://code.djangoproject.com/ticket/12386#comment:4>

Django

unread,
Jan 14, 2010, 2:06:12 AM1/14/10
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
---------------------------------------------------+------------------------
Reporter: ldevesine | Owner: nobody
Status: reopened | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Comment (by simonb):

It seems that 1.2 produces a different column name for the m2m field when
there are more than one m2m field in a model. I will attach a sample
project that demonstrates this.

--
Ticket URL: <http://code.djangoproject.com/ticket/12386#comment:5>

Django

unread,
Jan 14, 2010, 3:33:33 AM1/14/10
to djang...@holovaty.com, django-...@googlegroups.com
#12386: Automatic ManyToMany Fields in models defined in packages use invalid
column names
---------------------------------------------------+------------------------
Reporter: ldevesine | Owner: nobody
Status: reopened | Milestone:
Component: Database layer (models, ORM) | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by simonb):

* cc: bno...@gmail.com (added)

--
Ticket URL: <http://code.djangoproject.com/ticket/12386#comment:6>
Reply all
Reply to author
Forward
0 new messages