dbcore: Actually normalize RegexpQuery pattern

unintentionally, the pattern normalization added in
1c3a053ce5 was a no-op, and only value
normalization was actually applied (since self.pattern was left
unchanged)

This also helps with typing by ensuring that variables have fixed types
This commit is contained in:
wisp3rwind 2023-06-25 10:06:35 +02:00
parent b19b961035
commit 7fbf562d24

View file

@ -265,16 +265,17 @@ class RegexpQuery(StringFieldQuery):
"""
def __init__(self, field: str, pattern: str, fast: bool = True):
super().__init__(field, pattern, fast)
pattern = self._normalize(pattern)
try:
self.pattern = re.compile(self.pattern)
pattern_re = re.compile(pattern)
except re.error as exc:
# Invalid regular expression.
raise InvalidQueryArgumentValueError(pattern,
"a regular expression",
format(exc))
super().__init__(field, pattern_re, fast)
def col_clause(self):
return f" regexp({self.field}, ?)", [self.pattern.pattern]