From db9edfe7ac74001dbef11184081e623df335ff77 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 21 Nov 2024 10:37:28 -0500 Subject: [PATCH] mibioa/query: fix regression QuerySet.iterate() crash in certain cases Commit 6eaf2939 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. --- mibios/query.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mibios/query.py b/mibios/query.py index af5752c..5862258 100644 --- a/mibios/query.py +++ b/mibios/query.py @@ -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: @@ -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