diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-10-28 11:22:55 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-10-28 11:22:55 -0400 |
commit | 98c1dcc6bcade313a254fe11e8efa3c5b5ad959e (patch) | |
tree | 45b1c22fdcec957e86b9594ae3cf59e8c20ad06c /lib/sqlalchemy/sql | |
parent | c2c4fc14d592a022e192e5e63e015c0f0c00c893 (diff) | |
download | sqlalchemy-98c1dcc6bcade313a254fe11e8efa3c5b5ad959e.tar.gz |
- add a JSON warning for coerce_compared_value
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/type_api.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py index 3b5391234..bc67270eb 100644 --- a/lib/sqlalchemy/sql/type_api.py +++ b/lib/sqlalchemy/sql/type_api.py @@ -729,6 +729,26 @@ class TypeDecorator(SchemaEventTarget, TypeEngine): else: return self + .. warning:: + + Note that the **behavior of coerce_compared_value is not inherited + by default from that of the base type**. + If the :class:`.TypeDecorator` is augmenting a + type that requires special logic for certain types of operators, + this method **must** be overridden. A key example is when decorating + the :class:`.postgresql.JSON` and :class:`.postgresql.JSONB` types; + the default rules of :meth:`.TypeEngine.coerce_compared_value` should + be used in order to deal with operators like index operations:: + + class MyJsonType(TypeDecorator): + impl = postgresql.JSON + + def coerce_compared_value(self, op, value): + return self.impl.coerce_compared_value(op, value) + + Without the above step, index operations such as ``mycol['foo']`` + will cause the index value ``'foo'`` to be JSON encoded. + """ __visit_name__ = "type_decorator" |