Commit ddb84b2
committed
[IMP] util.explode_query_range: replace problematic
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
accomodate 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
`.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 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
```parallel_filter formatting1 parent badd3d8 commit ddb84b2
2 files changed
+46
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 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 | + | |
776 | 804 | | |
777 | 805 | | |
778 | 806 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
339 | 345 | | |
340 | 346 | | |
341 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
342 | 353 | | |
343 | 354 | | |
344 | 355 | | |
345 | 356 | | |
346 | 357 | | |
347 | | - | |
| 358 | + | |
348 | 359 | | |
349 | 360 | | |
350 | 361 | | |
| |||
376 | 387 | | |
377 | 388 | | |
378 | 389 | | |
| 390 | + | |
| 391 | + | |
379 | 392 | | |
380 | 393 | | |
381 | 394 | | |
| |||
387 | 400 | | |
388 | 401 | | |
389 | 402 | | |
390 | | - | |
| 403 | + | |
391 | 404 | | |
392 | 405 | | |
393 | 406 | | |
| |||
0 commit comments