mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Prevent duplicate groups in reference format fields (#4291)
This commit is contained in:
parent
4f029d4d81
commit
df4209801a
@ -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],
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user