Commit 58851b2
committed
[IMP] util.explode_query{,_range}: only format the
The usage of `str.format` to inject the parallel filter used to explode
queries is not robust to the presence of other curly braces. Examples:
1. `JSON` strings (typically to leverage their mapping capabilities):
See 79f3d71, where a query had to be
modified to accommodate that.
2. Hardcoded sets of curly braces:
```python
>>> "UPDATE t SET c = '{usage as literal characters}' WHERE {parallel_filter}".format(parallel_filter="…")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'usage as literal characters'
```
Which can be (unelegantly) solved adding even more braces, leveraging
one side effect of `str.format`:
```python
>>> "UPDATE t SET c = '{{usage as literal characters}}' WHERE {parallel_filter}".format(parallel_filter="…")
"UPDATE t SET c = '{usage as literal characters}' WHERE …"
```
3. Hardcoded single unpaired curly braces (AFAICT no way to solve this):
```python
>>> "UPDATE t SET c = 'this is an open curly brace = {' WHERE {parallel_filter}".format(parallel_filter="…")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: unexpected '{' in field name
```
```python
>>> "UPDATE t SET c = 'this is a close brace = }' WHERE {parallel_filter}".format(parallel_filter="…")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Single '}' encountered in format string
```
To circumvent this, we now use a dedicated Formatter that only handle
the `{parallel_filter}` placeholder. This has the advantage of still
deduplicate the doubled curly braces (see point 2 above) and thus being
retro-compatible.
This doesn't solve the single unpaired curly braces case, but this is
rare enough to be handled by other means.
closes #339
Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>{parallel_filter} placeholder1 parent 3e22c9a commit 58851b2
2 files changed
+79
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
768 | 768 | | |
769 | 769 | | |
770 | 770 | | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
771 | 807 | | |
772 | 808 | | |
773 | 809 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
223 | 261 | | |
224 | 262 | | |
225 | 263 | | |
| |||
256 | 294 | | |
257 | 295 | | |
258 | 296 | | |
259 | | - | |
| 297 | + | |
260 | 298 | | |
261 | 299 | | |
262 | 300 | | |
| |||
294 | 332 | | |
295 | 333 | | |
296 | 334 | | |
297 | | - | |
| 335 | + | |
298 | 336 | | |
299 | 337 | | |
300 | 338 | | |
| |||
335 | 373 | | |
336 | 374 | | |
337 | 375 | | |
338 | | - | |
| 376 | + | |
339 | 377 | | |
340 | 378 | | |
341 | | - | |
| 379 | + | |
| 380 | + | |
342 | 381 | | |
343 | 382 | | |
344 | 383 | | |
| |||
0 commit comments