diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-18 17:19:24 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-01-18 17:21:59 -0500 |
| commit | 692d05a5cc15cf3947055e9089b86ed99be3da46 (patch) | |
| tree | a83174c129e50a2915e78db87ae4498dbad4d812 /lib/sqlalchemy/sql/lambdas.py | |
| parent | 2bd622d27b44893a0dca5138e4acbff213771ddb (diff) | |
| download | sqlalchemy-692d05a5cc15cf3947055e9089b86ed99be3da46.tar.gz | |
reject methods as lambda SQL callables
Added an informative error message when a method object is passed to a SQL
construct. Previously, when such a callable were passed, as is a common
typographical error when dealing with method-chained SQL constructs, they
were interpreted as "lambda SQL" targets to be invoked at compilation time,
which would lead to silent failures. As this feature was not intended to be
used with methods, method objects are now rejected.
Fixes: #7032
Change-Id: If714715bd8c11557ab769ee3b1a24264b0b06acc
(cherry picked from commit e28ec27b599558b3e26ced106a972e8b4aa9e668)
Diffstat (limited to 'lib/sqlalchemy/sql/lambdas.py')
| -rw-r--r-- | lib/sqlalchemy/sql/lambdas.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/lambdas.py b/lib/sqlalchemy/sql/lambdas.py index e22f87167..5f9155998 100644 --- a/lib/sqlalchemy/sql/lambdas.py +++ b/lib/sqlalchemy/sql/lambdas.py @@ -5,6 +5,7 @@ # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php +import inspect import itertools import operator import sys @@ -619,6 +620,10 @@ class AnalyzedCode(object): return analyzed def __init__(self, fn, lambda_element, opts): + if inspect.ismethod(fn): + raise exc.ArgumentError( + "Method %s may not be passed as a SQL expression" % fn + ) closure = fn.__closure__ self.track_bound_values = ( |
