odoo/upgrade-util#142

Created by Upgrade, Edoardo Piroli (pied)

Blocked

label
odoo-dev:master-remove_explode_query_range_format-pied
head
faf43c0a67d31318a3391ebba8e2098c8b53217a
odoo/upgrade odoo/upgrade-util
master #6571 missing statuses missing r+ #142 missing statuses missing r+

[IMP] util.explode_query_range: replace problematic `parallel_filter`…

… formatting

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 79f3d7184285e39b04a6c032aec0e05de6565fe8, where a query had to be modified to accomodate that.

  1. Hardcoded sets of curly braces:
>>> "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:

>>> "UPDATE t SET c = '{{usage as literal characters}}' WHERE {parallel_filter}".format(parallel_filter="…")
"UPDATE t SET c = '{usage as literal characters}' WHERE …"
  1. Hardcoded curly braces (AFAICT no way to solve this):
>>> "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
>>> "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