Commit e1f7f15
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.{parallel_filter} placeholder1 parent fbd0b4f commit e1f7f15
2 files changed
Lines changed: 48 additions & 4 deletions
| 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 | + | |
771 | 795 | | |
772 | 796 | | |
773 | 797 | | |
| |||
| 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 | + | |
223 | 240 | | |
224 | 241 | | |
225 | 242 | | |
| |||
256 | 273 | | |
257 | 274 | | |
258 | 275 | | |
259 | | - | |
| 276 | + | |
260 | 277 | | |
261 | 278 | | |
262 | 279 | | |
| |||
286 | 303 | | |
287 | 304 | | |
288 | 305 | | |
| 306 | + | |
| 307 | + | |
289 | 308 | | |
290 | 309 | | |
291 | 310 | | |
| |||
294 | 313 | | |
295 | 314 | | |
296 | 315 | | |
297 | | - | |
| 316 | + | |
298 | 317 | | |
299 | 318 | | |
300 | 319 | | |
| |||
335 | 354 | | |
336 | 355 | | |
337 | 356 | | |
338 | | - | |
| 357 | + | |
339 | 358 | | |
340 | 359 | | |
341 | | - | |
| 360 | + | |
| 361 | + | |
342 | 362 | | |
343 | 363 | | |
344 | 364 | | |
| |||
0 commit comments