]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added the ``hashable=False`` flag to the PG :class:`.HSTORE` type, which
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 May 2014 17:58:08 +0000 (13:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 May 2014 17:58:31 +0000 (13:58 -0400)
is needed to allow the ORM to skip over trying to "hash" an ORM-mapped
HSTORE column when requesting it in a mixed column/entity list.
Patch courtesy Gunnlaugur Þór Briem.  Fixes #3053

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/postgresql/hstore.py
test/dialect/postgresql/test_types.py

index c3c0900a1d34d889adc91085545e3f8e6b4088c5..6b3c8310732b2bd5c8f7503771a8915bdd4eeb5f 100644 (file)
 .. changelog::
     :version: 0.8.7
 
+    .. change::
+        :tags: bug, postgresql
+        :versions: 0.9.5, 1.0.0
+        :tickets: 3053
+
+        Added the ``hashable=False`` flag to the PG :class:`.HSTORE` type, which
+        is needed to allow the ORM to skip over trying to "hash" an ORM-mapped
+        HSTORE column when requesting it in a mixed column/entity list.
+        Patch courtesy Gunnlaugur Þór Briem.
+
     .. change::
         :tags: bug, orm
         :versions: 0.9.5, 1.0.0
index 74419460bccea8495d27562e1caad099af0c125a..ee2c654a35ec227bfc67b6f9c9c3c3b4979c5d5a 100644 (file)
@@ -180,6 +180,7 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine):
     """
 
     __visit_name__ = 'HSTORE'
+    hashable = False
 
     class comparator_factory(sqltypes.Concatenable.Comparator):
         """Define comparison operations for :class:`.HSTORE`."""
index b30847bce2e873cc24674d8c860d27b1682c7d81..b94cc040a5f7a4e2083366617799792a44794cd1 100644 (file)
@@ -1375,6 +1375,21 @@ class HStoreRoundTripTest(fixtures.TablesTest):
         )
         self._assert_data([{r'key \"foo\"': r'value \"bar"\ xyz'}])
 
+    def test_orm_round_trip(self):
+        from sqlalchemy import orm
+        class Data(object):
+            def __init__(self, name, data):
+                self.name = name
+                self.data = data
+        orm.mapper(Data, self.tables.data_table)
+        s = orm.Session(testing.db)
+        d = Data(name='r1', data={"key1": "value1", "key2": "value2",
+                                    "key3": "value3"})
+        s.add(d)
+        eq_(
+            s.query(Data.data, Data).all(),
+            [(d.data, d)]
+        )
 class _RangeTypeMixin(object):
     __requires__ = 'range_types',
     __dialect__ = 'postgresql+psycopg2'