summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/exc.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-10-09 13:55:19 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-10-11 11:11:42 -0400
commit9488480abea15298ded6996aa13b42edf134e467 (patch)
tree6d6e6a0cac425ea848642d6d065dbecbd8f07a7b /lib/sqlalchemy/exc.py
parentcab08ea1834ac519f124789b835afa6832972b1c (diff)
downloadsqlalchemy-9488480abea15298ded6996aa13b42edf134e467.tar.gz
pass executemany context to _repr_params
Fixed bug where parameter repr as used in logging and error reporting needs additional context in order to distinguish between a list of parameters for a single statement and a list of parameter lists, as the "list of lists" structure could also indicate a single parameter list where the first parameter itself is a list, such as for an array parameter. The engine/connection now passes in an additional boolean indicating how the parameters should be considered. The only SQLAlchemy backend that expects arrays as parameters is that of psycopg2 which uses pyformat parameters, so this issue has not been too apparent, however as other drivers that use positional gain more features it is important that this be supported. It also eliminates the need for the parameter repr function to guess based on the parameter structure passed. Fixes: #4902 Change-Id: I086246ee0eb51484adbefd83e07295fa56576c5f
Diffstat (limited to 'lib/sqlalchemy/exc.py')
-rw-r--r--lib/sqlalchemy/exc.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index 1b3ac7ce2..79f786882 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -332,6 +332,8 @@ class StatementError(SQLAlchemyError):
orig = None
"""The DBAPI exception object."""
+ ismulti = None
+
def __init__(
self,
message,
@@ -340,11 +342,13 @@ class StatementError(SQLAlchemyError):
orig,
hide_parameters=False,
code=None,
+ ismulti=None,
):
SQLAlchemyError.__init__(self, message, code=code)
self.statement = statement
self.params = params
self.orig = orig
+ self.ismulti = ismulti
self.hide_parameters = hide_parameters
self.detail = []
@@ -360,6 +364,7 @@ class StatementError(SQLAlchemyError):
self.params,
self.orig,
self.hide_parameters,
+ self.ismulti,
),
)
@@ -381,7 +386,9 @@ class StatementError(SQLAlchemyError):
"[SQL parameters hidden due to hide_parameters=True]"
)
else:
- params_repr = util._repr_params(self.params, 10)
+ params_repr = util._repr_params(
+ self.params, 10, ismulti=self.ismulti
+ )
details.append("[parameters: %r]" % params_repr)
code_str = self._code_str()
if code_str:
@@ -424,6 +431,7 @@ class DBAPIError(StatementError):
hide_parameters=False,
connection_invalidated=False,
dialect=None,
+ ismulti=None,
):
# Don't ever wrap these, just return them directly as if
# DBAPIError didn't exist.
@@ -448,6 +456,7 @@ class DBAPIError(StatementError):
orig,
hide_parameters=hide_parameters,
code=orig.code,
+ ismulti=ismulti,
)
elif not isinstance(orig, dbapi_base_err) and statement:
return StatementError(
@@ -461,6 +470,7 @@ class DBAPIError(StatementError):
params,
orig,
hide_parameters=hide_parameters,
+ ismulti=ismulti,
)
glob = globals()
@@ -481,6 +491,7 @@ class DBAPIError(StatementError):
connection_invalidated=connection_invalidated,
hide_parameters=hide_parameters,
code=cls.code,
+ ismulti=ismulti,
)
def __reduce__(self):
@@ -492,6 +503,7 @@ class DBAPIError(StatementError):
self.orig,
self.hide_parameters,
self.connection_invalidated,
+ self.ismulti,
),
)
@@ -503,6 +515,7 @@ class DBAPIError(StatementError):
hide_parameters=False,
connection_invalidated=False,
code=None,
+ ismulti=None,
):
try:
text = str(orig)
@@ -517,6 +530,7 @@ class DBAPIError(StatementError):
orig,
hide_parameters,
code=code,
+ ismulti=ismulti,
)
self.connection_invalidated = connection_invalidated