[Django] #12559: Wrong SQL in M2M fields

0 views
Skip to first unread message

Django

unread,
Jan 9, 2010, 9:15:56 AM1/9/10
to djang...@holovaty.com, django-...@googlegroups.com
#12559: Wrong SQL in M2M fields
------------------------------------------+---------------------------------
Reporter: anonymous | Owner: nobody
Status: new | Milestone: 1.2
Component: Database layer (models, ORM) | Version: 1.2-alpha
Keywords: | Stage: Unreviewed
Has_patch: 0 |
------------------------------------------+---------------------------------
I have some strange problem after updating to the 1.2 alpha version.

My simplified model is

class Sticker(models.model):
telephones = models.ManyToManyField("account.Telephone")


when i run
sticker = Sticker.object.get(pk=1)
sticker.telephones.all()

Django generated sql is:
u'SELECT `account_telephone`.`id`, `account_telephone`.`tel_city`,
`account_telephone`.`tel_number`, `account_telephone`.`profile_id` FROM
`account_telephone` INNER JOIN `service_sticker_telephones` ON
(`account_telephone`.`id` =
`service_sticker_telephones`.`account.telephone_id`) WHERE
`service_sticker_telephones`.`sticker_id` = 1'

The wrong thing is service_sticker_telephones`.`account.telephone_id` , it
should be service_sticker_telephones`.`telephone_id`, but somehow the
application name was added. Even more interesting is that in my model i
have another M2M field that works well.

I tried to debug, but ORM layer is to complex for me. By the way, my
backend is MySQL.

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

Django

unread,
Jan 9, 2010, 10:04:47 AM1/9/10
to djang...@holovaty.com, django-...@googlegroups.com
#12559: Wrong SQL in M2M fields
---------------------------------------------------+------------------------
Reporter: anonymous | Owner: nobody
Status: new | Milestone: 1.2
Component: Database layer (models, ORM) | Version: 1.2-alpha
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by Alex):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0

Old description:

> I have some strange problem after updating to the 1.2 alpha version.
>
> My simplified model is
>
> class Sticker(models.model):
> telephones = models.ManyToManyField("account.Telephone")
>

> when i run
> sticker = Sticker.object.get(pk=1)
> sticker.telephones.all()
>
> Django generated sql is:
> u'SELECT `account_telephone`.`id`, `account_telephone`.`tel_city`,
> `account_telephone`.`tel_number`, `account_telephone`.`profile_id` FROM
> `account_telephone` INNER JOIN `service_sticker_telephones` ON
> (`account_telephone`.`id` =
> `service_sticker_telephones`.`account.telephone_id`) WHERE
> `service_sticker_telephones`.`sticker_id` = 1'
>
> The wrong thing is service_sticker_telephones`.`account.telephone_id` ,
> it should be service_sticker_telephones`.`telephone_id`, but somehow the
> application name was added. Even more interesting is that in my model i
> have another M2M field that works well.
>
> I tried to debug, but ORM layer is to complex for me. By the way, my
> backend is MySQL.

New description:

I have some strange problem after updating to the 1.2 alpha version.

My simplified model is
{{{
class Sticker(models.model):
telephones = models.ManyToManyField("account.Telephone")
}}}

when i run
{{{
sticker = Sticker.object.get(pk=1)
sticker.telephones.all()
}}}
Django generated sql is:
{{{
u'SELECT `account_telephone`.`id`, `account_telephone`.`tel_city`,
`account_telephone`.`tel_number`, `account_telephone`.`profile_id` FROM
`account_telephone` INNER JOIN `service_sticker_telephones` ON
(`account_telephone`.`id` =
`service_sticker_telephones`.`account.telephone_id`) WHERE
`service_sticker_telephones`.`sticker_id` = 1'
}}}
The wrong thing is service_sticker_telephones`.`account.telephone_id` , it
should be service_sticker_telephones`.`telephone_id`, but somehow the
application name was added. Even more interesting is that in my model i
have another M2M field that works well.

I tried to debug, but ORM layer is to complex for me. By the way, my
backend is MySQL.

Comment:

Fixed formatting, please use preview.

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

Django

unread,
Jan 14, 2010, 10:00:42 AM1/14/10
to djang...@holovaty.com, django-...@googlegroups.com
#12559: Wrong SQL in M2M fields
---------------------------------------------------+------------------------
Reporter: anonymous | Owner: nobody
Status: closed | Milestone: 1.2
Component: Database layer (models, ORM) | Version: 1.2-alpha
Resolution: duplicate | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by russellm):

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

Comment:

I'm fairly certain this is a duplicate of #12386, which I just fixed in
[12226]. Please reopen if I am mistaken.

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