--- /dev/null
+.. change::
+ :tags: bug, postgresql
+ :tickets: 10479
+
+ Fixed 2.0 regression caused by :ticket:`7744` where chains of expressions
+ involving PostgreSQL JSON operators combined with other operators such as
+ string concatenation would lose correct parenthesization, due to an
+ implementation detail specific to the PostgreSQL dialect.
except KeyError as err:
raise exc.UnsupportedCompilationError(self, operator_) from err
else:
+ kw["_in_operator_expression"] = True
return self._generate_delimited_list(
clauselist.clauses, opstring, **kw
)
def _generate_generic_binary(
self, binary, opstring, eager_grouping=False, **kw
):
- _in_binary = kw.get("_in_binary", False)
+ _in_operator_expression = kw.get("_in_operator_expression", False)
- kw["_in_binary"] = True
+ kw["_in_operator_expression"] = True
kw["_binary_op"] = binary.operator
text = (
binary.left._compiler_dispatch(
)
)
- if _in_binary and eager_grouping:
+ if _in_operator_expression and eager_grouping:
text = "(%s)" % text
return text
from sqlalchemy.dialects.postgresql import DOMAIN
from sqlalchemy.dialects.postgresql import ExcludeConstraint
from sqlalchemy.dialects.postgresql import insert
+from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import JSONPATH
from sqlalchemy.dialects.postgresql import Range
"AS jsonb_path_exists_1 FROM data",
)
+ @testing.combinations(
+ (lambda col: col["foo"] + " ", "(x -> %(x_1)s) || %(param_1)s"),
+ (
+ lambda col: col["foo"] + " " + col["bar"],
+ "(x -> %(x_1)s) || %(param_1)s || (x -> %(x_2)s)",
+ ),
+ argnames="expr, expected",
+ )
+ @testing.combinations((JSON(),), (JSONB(),), argnames="type_")
+ def test_eager_grouping_flag(self, expr, expected, type_):
+ """test #10479"""
+ col = Column("x", type_)
+
+ expr = testing.resolve_lambda(expr, col=col)
+
+ self.assert_compile(expr, expected)
+
def test_custom_object_hook(self):
# See issue #8884
from datetime import date
is_(col[5]["foo"].type._type_affinity, JSON)
is_(col[("a", "b", "c")].type._type_affinity, JSON)
+ @testing.combinations(
+ (lambda col: col["foo"] + " ", "(x -> :x_1) || :param_1"),
+ (
+ lambda col: col["foo"] + " " + col["bar"],
+ "(x -> :x_1) || :param_1 || (x -> :x_2)",
+ ),
+ )
+ def test_eager_grouping_flag(self, expr, expected):
+ """test #10479"""
+ col = Column("x", self.MyType())
+
+ expr = testing.resolve_lambda(expr, col=col)
+
+ self.assert_compile(expr, expected)
+
def test_getindex_literal_integer(self):
col = Column("x", self.MyType())