mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #23791 -- Corrected object type check for pk__in=qs
When the pk was a relation field, qs.filter(pk__in=qs) didn't work. In addition, fixed Restaurant.objects.filter(place=restaurant_instance), where place is an OneToOneField and the primary key of Restaurant. A big thank you to Josh for review and to Tim for review and cosmetic edits. Thanks to Beauhurst for commissioning the work on this ticket.
This commit is contained in:
committed by
Tim Graham
parent
736fb1838c
commit
9ed82154bd
@@ -23,7 +23,10 @@ def get_normalized_value(value, lhs):
|
||||
from django.db.models import Model
|
||||
if isinstance(value, Model):
|
||||
value_list = []
|
||||
# Account for one-to-one relations when sent a different model
|
||||
# A case like Restaurant.objects.filter(place=restaurant_instance),
|
||||
# where place is a OneToOneField and the primary key of Restaurant.
|
||||
if getattr(lhs.output_field, 'primary_key', False):
|
||||
return (value.pk,)
|
||||
sources = lhs.output_field.get_path_info()[-1].target_fields
|
||||
for source in sources:
|
||||
while not isinstance(value, source.model) and source.remote_field:
|
||||
|
||||
Reference in New Issue
Block a user