Skip to content

Commit d5d473c

Browse files
committed
Fixing collection export
1 parent 15ff359 commit d5d473c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

core/common/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def write_export_file(
229229
concepts_qs = Concept.sources.through.objects.filter(source_id=version.id)
230230
mappings_qs = Mapping.sources.through.objects.filter(source_id=version.id)
231231

232+
concept_id_field = 'concept_id' if hasattr(concepts_qs.model, 'concept_id') else 'id'
233+
mapping_id_field = 'mapping_id' if hasattr(mappings_qs.model, 'mapping_id') else 'id'
234+
232235
filters = {}
233236

234237
if not is_collection:
@@ -246,7 +249,9 @@ def write_export_file(
246249
start = 0
247250
while True:
248251
batch_ids = list(
249-
concepts_qs.order_by('-concept_id')[start:start + batch_size].values_list('concept_id', flat=True)
252+
concepts_qs.order_by(f'-{concept_id_field}')[start:start + batch_size].values_list(
253+
concept_id_field, flat=True
254+
)
250255
)
251256
if not batch_ids:
252257
break
@@ -296,7 +301,9 @@ def write_export_file(
296301
start = 0
297302
while True:
298303
batch_ids = list(
299-
mappings_qs.order_by('-mapping_id')[start:start + batch_size].values_list('mapping_id', flat=True)
304+
mappings_qs.order_by(f'-{mapping_id_field}')[start:start + batch_size].values_list(
305+
mapping_id_field, flat=True
306+
)
300307
)
301308
if not batch_ids:
302309
break

0 commit comments

Comments
 (0)