]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
HSTORE.comparator_factory should subclass Concatenable.Comparator
authorAudrius Kažukauskas <audrius@neutrino.lt>
Tue, 20 Nov 2012 22:26:20 +0000 (00:26 +0200)
committerAudrius Kažukauskas <audrius@neutrino.lt>
Tue, 20 Nov 2012 22:26:20 +0000 (00:26 +0200)
lib/sqlalchemy/dialects/postgresql/hstore.py
test/dialect/test_postgresql.py

index 8ac65b9126c175feaec7a641dd347ff7b6620d42..a6093d9f75c351237577d4d8a150f06873be3011 100644 (file)
@@ -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):
index 46dab3df91842bf992afb7cd6a4df440b7e4040f..0ca07ef2aaa560e7ae17b64ae4561a9872148276 100644 (file)
@@ -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'