Opened 10 years ago

Last modified 9 years ago

#23791 closed Bug

Subqueries with non-"id" OneToOneField primary keys try to join against the wrong column name — at Version 1

Reported by: ris Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: orm primary_key OneToOneField subquery values
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ris)

Hi, your favourite ORM obscure-query bug reporter again here...

Using Django 1.7.1 & postgres, example models.py:

class ModelA ( models.Model ):
	x = models.TextField ()

class ModelB ( models.Model ):
	a = models.OneToOneField ( ModelA , primary_key = True )

issuing the query

>>> ModelB.objects.filter ( pk__in = ModelB.objects.filter ( a__x = "abc" ) )

results in

FieldError: Cannot resolve keyword u'id' into field. Choices are: a, a_id

A workaround exists:

>>> ModelB.objects.filter ( pk__in = ModelB.objects.filter ( a__x = "abc" ).values ( "pk" ) )

which behaves correctly.

Change History (1)

comment:1 by ris, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top