Opened 9 years ago

Closed 9 years ago

#24998 closed Bug (duplicate)

ManyToManyField generating wrong query

Reported by: Arthur Rio Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: ManyToManyField, bad query
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Arthur Rio)

If two models have a ManyToManyField pointing to the same model, the query generated for the lookup is incorrect. I have created a repo on github with a simple test (https://github.com/arthurio/manytomanybug/releases/tag/v1.0) and you can also find the code enclosed as a .zip file.

There are 3 models:

  • Upload: that will be common to several other models.
  • FormA with a ManyToManyField to the Upload model.
  • FormB with a ManyToManyField to the Upload model.

When trying to do formAinstance.signature.all(), the query generated is using the FormB table to do the join instead of the FormA table.

Attachments (2)

manytomanybug-1.0.zip (10.3 KB ) - added by Arthur Rio 9 years ago.
Django project containing the test
manytomanybug-1.1.zip (10.3 KB ) - added by Arthur Rio 9 years ago.
Django project containing the test

Download all attachments as: .zip

Change History (6)

by Arthur Rio, 9 years ago

Attachment: manytomanybug-1.0.zip added

Django project containing the test

comment:1 by Arthur Rio, 9 years ago

Description: modified (diff)

by Arthur Rio, 9 years ago

Attachment: manytomanybug-1.1.zip added

Django project containing the test

comment:2 by Tim Graham, 9 years ago

This looks like it might be a duplicate of #24505 (fixed in master, but not 1.8). Can you reproduce the issue against master?

comment:3 by Arthur Rio, 9 years ago

If you define the related_name with a unique name, the bug goes away. There is probably something going on when setting the _hints of the related field.

Version 0, edited 9 years ago by Arthur Rio (next)

comment:4 by Arthur Rio, 9 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top