Commit 784ff29
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 79f3d71 commit 784ff29
2 files changed
+28
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
662 | 688 | | |
663 | 689 | | |
664 | 690 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
300 | | - | |
| 300 | + | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
0 commit comments