]> 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:36 +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 9115f1bc607c5fb95a9d575d9be68bb4a3c5162d..c21420b7d6410c4260db3a0ef658b87e8c713e9b 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 959bf47be91eec4e7729a1018d5ea8735de055c9..b1a0f8341a9ae479d517cd887802ac61170fccbd 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 9caae0898db70b21f46824091048b7066df4fcdb..1ae2f05043f2b156399ee53472251ebc0ce2d33b 100644 (file)
@@ -1400,6 +1400,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'