summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-03-30 17:52:10 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-30 17:52:10 -0400
commit07b63894cb8ff9529b406f196b5d7cb9af209e9e (patch)
tree066391964b639e4cba8e74e0808082f896f9937c /test
parent4eb4010c1a1c3e5c2529b9be9d8d56f1d6a4ec00 (diff)
downloadsqlalchemy-07b63894cb8ff9529b406f196b5d7cb9af209e9e.tar.gz
Track SchemaEventTarget types in as_mutable()
Fixed bug in :mod:`sqlalchemy.ext.mutable` where the :meth:`.Mutable.as_mutable` method would not track a type that had been copied using :meth:`.TypeEngine.copy`. This became more of a regression in 1.1 compared to 1.0 because the :class:`.TypeDecorator` class is now a subclass of :class:`.SchemaEventTarget`, which among other things indicates to the parent :class:`.Column` that the type should be copied when the :class:`.Column` is. These copies are common when using declarative with mixins or abstract classes. Change-Id: Ib04df862c58263185dbae686c548fea3e12c46f1 Fixes: #3950
Diffstat (limited to 'test')
-rw-r--r--test/ext/test_mutable.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/ext/test_mutable.py b/test/ext/test_mutable.py
index 81d2136e3..5b6d3e7cf 100644
--- a/test/ext/test_mutable.py
+++ b/test/ext/test_mutable.py
@@ -725,6 +725,49 @@ class MutableWithScalarJSONTest(_MutableDictTestBase, fixtures.MappedTest):
self._test_non_mutable()
+class MutableColumnCopyJSONTest(_MutableDictTestBase, fixtures.MappedTest):
+
+ @classmethod
+ def define_tables(cls, metadata):
+ import json
+ from sqlalchemy.ext.declarative import declarative_base
+
+ class JSONEncodedDict(TypeDecorator):
+ impl = VARCHAR(50)
+
+ def process_bind_param(self, value, dialect):
+ if value is not None:
+ value = json.dumps(value)
+
+ return value
+
+ def process_result_value(self, value, dialect):
+ if value is not None:
+ value = json.loads(value)
+ return value
+
+ MutableDict = cls._type_fixture()
+
+ Base = declarative_base(metadata=metadata)
+
+ class AbstractFoo(Base):
+ __abstract__ = True
+
+ id = Column(Integer, primary_key=True,
+ test_needs_autoincrement=True)
+ data = Column(MutableDict.as_mutable(JSONEncodedDict))
+ non_mutable_data = Column(JSONEncodedDict)
+ unrelated_data = Column(String(50))
+
+ class Foo(AbstractFoo):
+ __tablename__ = "foo"
+
+ assert Foo.data.property.columns[0].type is not AbstractFoo.data.type
+
+ def test_non_mutable(self):
+ self._test_non_mutable()
+
+
class MutableListWithScalarPickleTest(_MutableListTestBase,
fixtures.MappedTest):