diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-05-25 13:58:08 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-05-25 13:58:08 -0400 |
| commit | e384347ffb9b29fca146df54284e96a567adae9c (patch) | |
| tree | bac85461583669e0e149407934ba97182fefd610 | |
| parent | 95b10c4e8e59cf2509ba5d90a03341d74f93d164 (diff) | |
| download | sqlalchemy-e384347ffb9b29fca146df54284e96a567adae9c.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.rst | 10 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/hstore.py | 1 | ||||
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 15 |
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' |
