Summary
The rewrite_update() function in src/sqlalchemy_cratedb/compiler.py constructs bind parameter keys for partial ObjectType updates using the following format:
newparams["{0}['{1}']".format(key, subkey)] = subval
# e.g., key="data", subkey="x" → "data['x']"
SQLAlchemy's IdentifierPreparer then sanitizes bind param names by replacing [ → _ and ] → _, but leaves the single quotes intact, resulting in keys like data_'x'_. This leaks internal bracket notation into the parameter dictionary, which is surprising for downstream consumers.
Proposed Change
Change how parameter keys are constructed in rewrite_update() to avoid embedding bracket notation:
# Before
newparams["{0}['{1}']".format(key, subkey)] = subval # → data_'x'_ after sanitization
# After
newparams["{0}__{1}_".format(key, subkey)] = subval # → data__x_ after sanitization
This would produce clean, quote-free bind parameter names that better reflect the column and sub-key relationship.
Related Context
- The
visit_update implementations in compat/core10.py, compat/core14.py, and compat/core20.py contain a deactivated SQLAlchemy sanity check ("Unconsumed column names") that was disabled precisely because of keys like data['nested'] not being recognised. Fixing the key format here may also allow re-enabling or simplifying that workaround.
References
Summary
The
rewrite_update()function insrc/sqlalchemy_cratedb/compiler.pyconstructs bind parameter keys for partialObjectTypeupdates using the following format:SQLAlchemy's
IdentifierPreparerthen sanitizes bind param names by replacing[→_and]→_, but leaves the single quotes intact, resulting in keys likedata_'x'_. This leaks internal bracket notation into the parameter dictionary, which is surprising for downstream consumers.Proposed Change
Change how parameter keys are constructed in
rewrite_update()to avoid embedding bracket notation:This would produce clean, quote-free bind parameter names that better reflect the column and sub-key relationship.
Related Context
visit_updateimplementations incompat/core10.py,compat/core14.py, andcompat/core20.pycontain a deactivated SQLAlchemy sanity check ("Unconsumed column names") that was disabled precisely because of keys likedata['nested']not being recognised. Fixing the key format here may also allow re-enabling or simplifying that workaround.References
paramstyle="pyformat", following crate-python 2.2.0 #266: Migrate toparamstyle="pyformat", following crate-python 2.2.0 #266paramstyle="pyformat", following crate-python 2.2.0 #266 (comment)