[Django] #24954: ManyToMany field fails with non-integer ids

19 views
Skip to first unread message

Django

unread,
Jun 8, 2015, 12:01:15 PM6/8/15
to django-...@googlegroups.com
#24954: ManyToMany field fails with non-integer ids
----------------------------------------------+----------------------------
Reporter: cloudOver | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords: ManyToMany,
| UUID
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------------
I have models with manyToMany field and uuid based primary keys, e.g.:

{{{
class SomeModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
blockers = models.ManyToManyField('self', symmetrical=False,
blank=True)
....
}}}
In 1.8 django creates new table, which has integer-based identifier for
ManyToMany relationship:
{{{
describe overCluster_somemodel_blockers;
+--------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| from_somemodel_id | int(11) | NO | MUL | NULL | |
| to_somemodel_id | int(11) | NO | MUL | NULL | |
+--------------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
}}}
Foreign fields from that additional table fails (integer field points to
uuid fields). The same problem exists with string based id. I haven't
found that bug in sqlite backend.

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

Django

unread,
Jun 9, 2015, 3:53:48 AM6/9/15
to django-...@googlegroups.com
#24954: ManyToMany field fails with non-integer ids
----------------------------------+--------------------------------------

Reporter: cloudOver | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:

Keywords: ManyToMany, UUID | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by cloudOver):

* needs_better_patch: => 0
* component: Database layer (models, ORM) => Migrations
* needs_tests: => 0
* needs_docs: => 0


Comment:

The problem refers to migration system. In some cases, Django migration
didn't change types of foreign keys in ManyToMany.

--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:1>

Django

unread,
Jun 10, 2015, 6:22:14 AM6/10/15
to django-...@googlegroups.com
#24954: ManyToMany field fails with non-integer ids
----------------------------------+--------------------------------------

Reporter: cloudOver | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: ManyToMany, UUID | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by synotna):

This also applies to changing the primary key of the referenced model; a
migration to update the existing column is not detected/generated

--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:2>

Django

unread,
Jun 10, 2015, 11:49:13 AM6/10/15
to django-...@googlegroups.com
#24954: Adding an explicit UUID id doesn't change type of ManyToMany fields
pointing to it
----------------------------------+------------------------------------

Reporter: cloudOver | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: ManyToMany, UUID | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

I could reproduce this with an initial model (implicit `AutoField` `id`):
{{{
class SomeModel(models.Model):


blockers = models.ManyToManyField('self', symmetrical=False,
blank=True)
}}}

then adding an explicit `id` as `id = models.UUIDField(primary_key=True,
default=uuid.uuid4, editable=False)`. The `from_X_id` and `to_X_id` fields
in the many to many table where still 'integer' type (SQLite).

--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:3>

Django

unread,
Oct 5, 2015, 4:13:14 AM10/5/15
to django-...@googlegroups.com
#24954: Adding an explicit UUID id doesn't change type of ManyToMany fields
pointing to it
----------------------------------+------------------------------------
Reporter: cloudOver | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: ManyToMany, UUID | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by BlindHunter):

* Attachment "test_many2many_intermediate_table_not_migrated.diff" added.

Many to many intermediate table is not migrated.

Django

unread,
May 25, 2016, 3:36:07 AM5/25/16
to django-...@googlegroups.com
#24954: Adding an explicit UUID id doesn't change type of ManyToMany fields
pointing to it
----------------------------------+-------------------------------------
Reporter: cloudOver | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: duplicate

Keywords: ManyToMany, UUID | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+-------------------------------------
Changes (by charettes):

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


Comment:

Duplicate of #25012 as `ManyToManyField` uses `ForeignKey` under the hood.

--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:4>

Reply all
Reply to author
Forward
0 new messages