]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a JSON warning for coerce_compared_value
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Oct 2015 15:22:55 +0000 (11:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Oct 2015 15:24:20 +0000 (11:24 -0400)
(cherry picked from commit 98c1dcc6bcade313a254fe11e8efa3c5b5ad959e)

lib/sqlalchemy/sql/type_api.py

index a55eed98114663b79889992f70c24751d34d8a43..6bedfacc6457a0414f9948ae76b31256bc5e1cd2 100644 (file)
@@ -656,6 +656,26 @@ class TypeDecorator(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"