2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Prevent duplicate groups in reference format fields (#4291)

This commit is contained in:
Oliver
2023-02-02 11:32:47 +11:00
committed by GitHub
parent 4f029d4d81
commit df4209801a
2 changed files with 12 additions and 2 deletions

View File

@ -16,11 +16,21 @@ def parse_format_string(fmt_string: str) -> dict:
info = {} info = {}
seen_groups = set()
for group in groups: for group in groups:
# Skip any group which does not have a named value # Skip any group which does not have a named value
if not group[1]: if not group[1]:
continue 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]] = { info[group[1]] = {
'format': group[1], 'format': group[1],
'prefix': group[0], 'prefix': group[0],

View File

@ -233,9 +233,9 @@ class ReferenceIndexingMixin(models.Model):
try: try:
info = InvenTree.format.parse_format_string(pattern) info = InvenTree.format.parse_format_string(pattern)
except Exception: except Exception as exc:
raise ValidationError({ raise ValidationError({
"value": _("Improperly formatted pattern"), "value": _("Improperly formatted pattern") + ": " + str(exc)
}) })
# Check that only 'allowed' keys are provided # Check that only 'allowed' keys are provided