Skip to content

Commit

Permalink
fix: a not caseSesitive bone should lock the lower value
Browse files Browse the repository at this point in the history
The idea of _caseINSensitive_ bones is that the upper/lower case
does not matter and `"Test"`, `"test"`, and `"TEST"` are equivalent.

If you now have a unique contstraint `UniqueLockMethod.SameValue`,
it is still possible to create the three entries.

---

Alternatively, we could of course also introduce `UniqueLockMethod.EqualValue`,
which controls this even more precisely.
  • Loading branch information
sveneberth committed Jan 22, 2025
1 parent a090e5b commit 4f290c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/viur/core/bones/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ def keyHash(key):
return f"K-{keyHash(value)}"
raise NotImplementedError(f"Type {type(value)} can't be safely used in an uniquePropertyIndex")

logging.debug(f"_hashValueForUniquePropertyIndex: {value=}")
if not value and not self.unique.lockEmpty:
return [] # We are zero/empty string and these should not be locked
if not self.multiple:
Expand Down
3 changes: 3 additions & 0 deletions src/viur/core/bones/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ def getUniquePropertyIndexValues(self, skel: "SkeletonInstance", name: str) -> l
# Not yet implemented as it's unclear if we should keep each language distinct or not
raise NotImplementedError()

if not self.caseSensitive and (val := skel[name]) is not None:
return self._hashValueForUniquePropertyIndex(val.lower())

return super().getUniquePropertyIndexValues(skel, name)

def refresh(self, skel: "SkeletonInstance", bone_name: str) -> None:
Expand Down

0 comments on commit 4f290c6

Please sign in to comment.