mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-10 02:47:49 +00:00
Prevent duplicate groups in reference format fields (#4291)
This commit is contained in:
1 parent
4f029d4d81
commit
df4209801a
2 files changed
+12
-2
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user