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 Initial Version

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

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

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

results in

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

A workaround exists:

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

which behaves correctly.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top