[Sqlalchemy-tickets] Issue #3694: Incorrect processing of has_key parameter on JSONB columns with c
Brought to you by:
zzzeek
From: Arnout v. M. <iss...@bi...> - 2016-04-14 20:17:20
|
New issue 3694: Incorrect processing of has_key parameter on JSONB columns with custom types https://bitbucket.org/zzzeek/sqlalchemy/issues/3694/incorrect-processing-of-has_key-parameter Arnout van Meer: In our codebase we have a custom type based on JSONB and noticed has_key wasn't working. This seems to be due to parameter to has_key getting run through the bind processor which results in unintended quoting of the parameter string. Repro case, tested with 1.0.12: ``` #!python from sqlalchemy import create_engine, Column, Table, MetaData, select, types from sqlalchemy.dialects.postgresql import JSONB class CustomJSONBType(types.TypeDecorator): impl = JSONB e = create_engine("postgresql://localhost/jsonb_test", echo=True) c = e.connect() t = c.begin() # this works table = Table('jsonb_test', MetaData(), Column('data', JSONB)) table.create(c) c.execute(table.insert(), [{"data": {"x": 2}}]) assert c.scalar(select([table]).where(table.c.data.has_key('x'))) # this doesn't work table = Table('custom_jsonb_test', MetaData(), Column('data', CustomJSONBType)) table.create(c) c.execute(table.insert(), [{"data": {"x": 2}}]) assert c.scalar(select([table]).where(table.c.data.has_key('x'))) ``` |