summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-23 10:19:39 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-23 10:54:54 -0400
commit373e960cb4448d1498d0a47fd35c97f83170f87e (patch)
tree53f5a34a650dae44eeb77d962d8ff0772c9c822f /test/sql
parent8971e27a9b5d1923d36f35c2ba1aaaf46f596308 (diff)
downloadsqlalchemy-373e960cb4448d1498d0a47fd35c97f83170f87e.tar.gz
dont assume ClauseElement in attributes, coercions
Fixed two distinct issues, each of which would come into play under certain circumstances, most likely however one which is a common mis-configuration in :class:`_hybrid.hybrid_property`, where the "expression" implementation would return a non :class:`_sql.ClauseElement` such as a boolean value. For both issues, 1.3's behavior was to silently ignore the mis-configuration and ultimately attempt to interpret the value as a SQL expression, which would lead to an incorrect query. * Fixed issue regarding interaction of the attribute system with hybrid_property, where if the ``__clause_element__()`` method of the attribute returned a non-:class:`_sql.ClauseElement` object, an internal ``AttributeError`` would lead the attribute to return the ``expression`` function on the hybrid_property itself, as the attribute error was against the name ``.expression`` which would invoke the ``__getattr__()`` method as a fallback. This now raises explicitly. In 1.3 the non-:class:`_sql.ClauseElement` was returned directly. * Fixed issue in SQL argument coercions system where passing the wrong kind of object to methods that expect column expressions would fail if the object were altogether not a SQLAlchemy object, such as a Python function, in cases where the object were not just coerced into a bound value. Again 1.3 did not have a comprehensive argument coercion system so this case would also pass silently. Fixes: #6350 Change-Id: I5bba0a6b27f45e5f8ebadfd6d511fa773388ef7c
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_roles.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/sql/test_roles.py b/test/sql/test_roles.py
index 997311071..37f75594b 100644
--- a/test/sql/test_roles.py
+++ b/test/sql/test_roles.py
@@ -209,6 +209,23 @@ class RoleTest(fixtures.TestBase):
):
expect(roles.ExpressionElementRole, t.select().alias())
+ def test_raise_on_regular_python_obj_for_expr(self):
+ """test #6350"""
+
+ def some_function():
+ pass
+
+ class Thing(object):
+ def __clause_element__(self):
+ return some_function
+
+ with testing.expect_raises_message(
+ exc.ArgumentError,
+ r"SQL expression element expected, got "
+ "<function .*some_function .* resolved from <.*Thing object .*",
+ ):
+ expect(roles.ExpressionElementRole, Thing())
+
def test_statement_text_coercion(self):
with testing.expect_deprecated_20(
"Using plain strings to indicate SQL statements"