FORMAT_QMARK_REGEX in sqlite backend does not work as expected
|Reported by:||anonymous||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3-rc|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
FORMAT_QMARK_REGEX is not correct (in django/db/backends/sqlite3/base.py).
It uses a lookahead assertion trying to not match if the char before the "%s" is not "%" but lookahead assertion can't be used to do that (it is for looking ahead not behind).
In the regex '(?!..)b' applied on 'abc' the '..' will match 'bc' so: - re.search(r'(?!a)b','abc') => match 'b' - re.search(r'(?!b)b','abc') => no match
I don't think this regex could be writen with lookhead assertions.
A possible solution could be:
re.compile(r'(^|[^%])%s').sub(r'\1?','%s %%s %s')
Change History (3)
comment:1 Changed 4 years ago by aaugustin
- Easy pickings set
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted