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
1 changed files with 10 additions and 8 deletions

View File

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