Skip to content

Commit ae5716d

Browse files
Bom export fix (#10163)
* Bug fix for BOM exporter - Handle edge case with null manufacturer value * Mark failed data exports
1 parent e82965e commit ae5716d

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/backend/InvenTree/data_exporter/mixins.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,13 @@ def export_data(
351351
filename = export_plugin.generate_filename(
352352
serializer_class.Meta.model, export_format
353353
)
354-
except Exception:
354+
except Exception as e:
355355
InvenTree.exceptions.log_error(
356356
'generate_filename', plugin=export_plugin.slug
357357
)
358+
359+
output.mark_failure(error=str(e))
360+
358361
raise ValidationError(export_error)
359362

360363
# The provided plugin is responsible for exporting the data
@@ -364,8 +367,12 @@ def export_data(
364367
queryset, serializer_class, headers, export_context, output
365368
)
366369

367-
except Exception:
370+
except Exception as e:
368371
InvenTree.exceptions.log_error('export_data', plugin=export_plugin.slug)
372+
373+
# Log the error against the output object
374+
output.mark_failure(error=str(e))
375+
369376
raise ValidationError(export_error)
370377

371378
if not isinstance(data, list):
@@ -377,17 +384,21 @@ def export_data(
377384
if hasattr(export_plugin, 'update_headers'):
378385
try:
379386
headers = export_plugin.update_headers(headers, export_context)
380-
except Exception:
387+
except Exception as e:
381388
InvenTree.exceptions.log_error(
382389
'update_headers', plugin=export_plugin.slug
383390
)
391+
392+
output.mark_failure(error=str(e))
393+
384394
raise ValidationError(export_error)
385395

386396
# Now, export the data to file
387397
try:
388398
datafile = serializer.export_to_file(data, headers, export_format)
389-
except Exception:
399+
except Exception as e:
390400
InvenTree.exceptions.log_error('export_to_file', plugin=export_plugin.slug)
401+
output.mark_failure(error=str(e))
391402
raise ValidationError(_('Error occurred during data export'))
392403

393404
# Update the output object with the exported data

src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ def get_supplier_data(self, bom_item: BomItem) -> dict:
275275
for supplier_part in bom_item.sub_part.supplier_parts.all():
276276
manufacturer_part = supplier_part.manufacturer_part
277277
supplier_part_data.update({
278-
f'supplier_name_{idx}': supplier_part.supplier.name,
278+
f'supplier_name_{idx}': supplier_part.supplier.name
279+
if supplier_part.supplier
280+
else '',
279281
f'supplier_sku_{idx}': supplier_part.SKU,
280282
f'supplier_mpn_{idx}': manufacturer_part.MPN
281283
if manufacturer_part
@@ -296,7 +298,9 @@ def get_manufacturer_data(self, bom_item: BomItem) -> dict:
296298

297299
for manufacturer_part in bom_item.sub_part.manufacturer_parts.all():
298300
manufacturer_part_data.update({
299-
f'manufacturer_name_{idx}': manufacturer_part.manufacturer.name,
301+
f'manufacturer_name_{idx}': manufacturer_part.manufacturer.name
302+
if manufacturer_part.manufacturer
303+
else '',
300304
f'manufacturer_mpn_{idx}': manufacturer_part.MPN,
301305
})
302306

0 commit comments

Comments
 (0)