From 21cb06d1c077cb865be96108bf2d2f7961bbc868 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 25 May 2014 13:58:08 -0400 Subject: [PATCH] =?utf8?q?-=20Added=20the=20``hashable=3DFalse``=20flag=20?= =?utf8?q?to=20the=20PG=20:class:`.HSTORE`=20type,=20which=20is=20needed?= =?utf8?q?=20to=20allow=20the=20ORM=20to=20skip=20over=20trying=20to=20"ha?= =?utf8?q?sh"=20an=20ORM-mapped=20HSTORE=20column=20when=20requesting=20it?= =?utf8?q?=20in=20a=20mixed=20column/entity=20list.=20Patch=20courtesy=20G?= =?utf8?q?unnlaugur=20=C3=9E=C3=B3r=20Briem.=20=20Fixes=20#3053?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc/build/changelog/changelog_08.rst | 10 ++++++++++ lib/sqlalchemy/dialects/postgresql/hstore.py | 1 + test/dialect/postgresql/test_types.py | 15 +++++++++++++++ 3 files changed, 26 insertions(+) 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' -- 2.47.3