Skip to content

Commit

Permalink
Tentatively pull in changes for #2742 prefetch fix.
Browse files Browse the repository at this point in the history
I believe the issue is that the state of `fks` / `backrefs` could be
incorrect if the loop finds relationships but does not exit (due to
failing the 2nd clause which checks the target_model).
  • Loading branch information
coleifer committed Jun 14, 2023
1 parent f06d61e commit 2887ed9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -7955,8 +7955,8 @@ def prefetch_add_subquery(sq, subqueries, prefetch_type):
isinstance(subquery, ModelAlias):
subquery = subquery.select()
subquery_model = subquery.model
fks = backrefs = None
for j in reversed(range(i + 1)):
fks = backrefs = None
fixed = fixed_queries[j]
last_query = fixed.query
last_model = last_obj = fixed.model
Expand All @@ -7972,7 +7972,7 @@ def prefetch_add_subquery(sq, subqueries, prefetch_type):
(target_model is None)):
break

if not fks and not backrefs:
else:
tgt_err = ' using %s' % target_model if target_model else ''
raise AttributeError('Error: unable to find foreign key for '
'query: %s%s' % (subquery, tgt_err))
Expand Down

0 comments on commit 2887ed9

Please sign in to comment.