From: Audrius Kažukauskas Date: Tue, 20 Nov 2012 22:26:20 +0000 (+0200) Subject: HSTORE.comparator_factory should subclass Concatenable.Comparator X-Git-Tag: rel_0_8_0b2~25^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=64505dcd2871bfe67f682d67df937b713c4213a6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git HSTORE.comparator_factory should subclass Concatenable.Comparator --- diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index 8ac65b9126..a6093d9f75 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -47,7 +47,7 @@ def _parse_error(hstore_str, pos): residual = residual[:-1] + '[...]' return "After %r, could not parse residual at position %d: %r" % ( - parsed_tail, pos, residual) + parsed_tail, pos, residual) def _parse_hstore(hstore_str): @@ -173,7 +173,7 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): __visit_name__ = 'HSTORE' - class comparator_factory(sqltypes.TypeEngine.Comparator): + class comparator_factory(sqltypes.Concatenable.Comparator): """Define comparison operations for :class:`.HSTORE`.""" def has_key(self, other): @@ -218,12 +218,6 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): """ return self.expr.op('->', precedence=5)(other) - def __add__(self, other): - """HStore expression. Merge the left and right hstore expressions, - with duplicate keys taking the value from the right expression. - """ - return self.expr.concat(other) - def delete(self, key): """HStore expression. Returns the contents of this hstore with the given key deleted. Note that the key may be a SQLA expression. @@ -262,7 +256,8 @@ class HSTORE(sqltypes.Concatenable, sqltypes.TypeEngine): return op, sqltypes.Boolean elif op.opstring == '->': return op, sqltypes.Text - return op, other_comparator.type + return sqltypes.Concatenable.Comparator.\ + _adapt_expression(self, op, other_comparator) def bind_processor(self, dialect): def process(value): diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 46dab3df91..0ca07ef2aa 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -2826,6 +2826,7 @@ class HStoreTest(fixtures.TestBase): '"key2"=>"value2", "key1"=>"value1", ' 'crapcrapcrap, "key3"=>"value3"' ) + def test_result_deserialize_default(self): from sqlalchemy.engine import default @@ -2986,8 +2987,8 @@ class HStoreTest(fixtures.TestBase): def test_cols_concat_op(self): self._test_cols( - self.hashcol + self.hashcol, - "test_table.hash || test_table.hash AS anon_1", + hstore('foo', 'bar') + self.hashcol, + "hstore(%(param_1)s, %(param_2)s) || test_table.hash AS anon_1", True ) @@ -3026,6 +3027,7 @@ class HStoreTest(fixtures.TestBase): True ) + class HStoreRoundTripTest(fixtures.TablesTest): __requires__ = 'hstore', __dialect__ = 'postgresql'