diff --git a/InvenTree/InvenTree/format.py b/InvenTree/InvenTree/format.py index 9df8211972..341d6a79fc 100644 --- a/InvenTree/InvenTree/format.py +++ b/InvenTree/InvenTree/format.py @@ -16,11 +16,21 @@ def parse_format_string(fmt_string: str) -> dict: info = {} + seen_groups = set() + for group in groups: # Skip any group which does not have a named value if not group[1]: continue + name = group[1] + + # Check for duplicate named groups + if name in seen_groups: + raise ValueError(f"Duplicate group '{name}'") + else: + seen_groups.add(name) + info[group[1]] = { 'format': group[1], 'prefix': group[0], diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index cd15800e55..3a3dacd04b 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -233,9 +233,9 @@ class ReferenceIndexingMixin(models.Model): try: info = InvenTree.format.parse_format_string(pattern) - except Exception: + except Exception as exc: raise ValidationError({ - "value": _("Improperly formatted pattern"), + "value": _("Improperly formatted pattern") + ": " + str(exc) }) # Check that only 'allowed' keys are provided