summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-05-25 13:58:08 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-05-25 13:58:31 -0400
commit64e887b2e399971513b2761979bb2f740816d4b7 (patch)
treec1b6b213f1899a65e243c2f41116b393e7274988
parent7dc497be982e5d09c3f2be8ebbac7537b31882a4 (diff)
downloadsqlalchemy-64e887b2e399971513b2761979bb2f740816d4b7.tar.gz
- 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. Fixes #3053
-rw-r--r--doc/build/changelog/changelog_08.rst10
-rw-r--r--lib/sqlalchemy/dialects/postgresql/hstore.py1
-rw-r--r--test/dialect/postgresql/test_types.py15
3 files changed, 26 insertions, 0 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst
index c3c0900a1..6b3c83107 100644
--- a/doc/build/changelog/changelog_08.rst
+++ b/doc/build/changelog/changelog_08.rst
@@ -12,6 +12,16 @@
: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
:tickets: 3055
diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py
index 74419460b..ee2c654a3 100644
--- a/lib/sqlalchemy/dialects/postgresql/hstore.py
+++ b/lib/sqlalchemy/dialects/postgresql/hstore.py
@@ -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`."""
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py
index b30847bce..b94cc040a 100644
--- a/test/dialect/postgresql/test_types.py
+++ b/test/dialect/postgresql/test_types.py
@@ -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'