diff options
| author | Tim Graham <timograham@gmail.com> | 2016-05-28 09:14:02 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-04 08:04:51 -0400 |
| commit | e2296e7f0acf9c50868ab997ba565c1f47beb45b (patch) | |
| tree | b4765517f4bd76194a36a33a6a44b62ce06f3e7b /django/db | |
| parent | 54febdb8be7c9793caae9c781f4d6b7cbbdcd900 (diff) | |
Fixed #26667 -- Fixed a regression in queries on a OneToOneField that has to_field and primary_key=True.
Thanks Simon Charette for review.
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/models/fields/related_lookups.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/django/db/models/fields/related_lookups.py b/django/db/models/fields/related_lookups.py index 3123e94073..5454031c2a 100644 --- a/django/db/models/fields/related_lookups.py +++ b/django/db/models/fields/related_lookups.py @@ -24,15 +24,16 @@ def get_normalized_value(value, lhs): from django.db.models import Model if isinstance(value, Model): value_list = [] - # 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: source = source.remote_field.model._meta.get_field(source.remote_field.field_name) - value_list.append(getattr(value, source.attname)) + try: + value_list.append(getattr(value, source.attname)) + except AttributeError: + # A case like Restaurant.objects.filter(place=restaurant_instance), + # where place is a OneToOneField and the primary key of Restaurant. + return (value.pk,) return tuple(value_list) if not isinstance(value, tuple): return (value,) |
