Skip to content

Commit

Permalink
mibioa/query: fix regression QuerySet.iterate() crash in certain cases
Browse files Browse the repository at this point in the history
Commit 6eaf293 caused crash in e.g. values_list().iterate(cache=True)
as there a FK field's attname is automatically listed as output field.
This fix adds conditional code allowing either field_name or attname, as
needed.
  • Loading branch information
robert102 committed Nov 21, 2024
1 parent a879fb7 commit db9edfe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mibios/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,14 @@ def update_bin(self, queryset):
get_fk = attrgetter(self.attname)
else:
# values list queryset
get_fk = itemgetter(
queryset.get_output_field_names().index(self.field_name)
)
try:
pos = queryset.get_output_field_names().index(self.field_name)
except ValueError:
# field_name is not in list, try attname
pos = queryset.get_output_field_names().index(self.attname)

get_fk = itemgetter(pos)
del pos

missing = set()
for i in queryset:
Expand Down Expand Up @@ -508,7 +513,7 @@ def _iter(self):
"""
The iterator/generator yielding the data.
inheriting classes must implement this
Must be provided by implementing class.
"""
raise NotImplementedError

Expand Down

0 comments on commit db9edfe

Please sign in to comment.