1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Merged nested if statements in select_related_descend().

This commit is contained in:
Simon Charette 2022-08-30 06:22:33 +02:00 committed by Mariusz Felisiak
parent 411a6ec93a
commit 60613ef516

View File

@ -285,14 +285,16 @@ def select_related_descend(field, restricted, requested, load_fields, reverse=Fa
return False
if not restricted and field.null:
return False
if load_fields:
if field.attname not in load_fields:
if restricted and field.name in requested:
msg = (
"Field %s.%s cannot be both deferred and traversed using "
"select_related at the same time."
) % (field.model._meta.object_name, field.name)
raise FieldError(msg)
if (
restricted
and load_fields
and field.name in requested
and field.attname not in load_fields
):
raise FieldError(
f"Field {field.model._meta.object_name}.{field.name} cannot be both "
"deferred and traversed using select_related at the same time."
)
return True