From: Mike Bayer Date: Sun, 25 May 2014 17:58:08 +0000 (-0400) Subject: - Added the ``hashable=False`` flag to the PG :class:`.HSTORE` type, which X-Git-Tag: rel_0_8_7~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21cb06d1c077cb865be96108bf2d2f7961bbc868;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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 --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 9115f1bc60..c21420b7d6 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,6 +11,16 @@ .. 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 diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index 959bf47be9..b1a0f8341a 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 9caae0898d..1ae2f05043 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -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'