summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/assertions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-12-08 11:00:31 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-12-08 17:37:25 -0500
commit8a152ec391118a05ac54974d0f013cf0e99c7832 (patch)
tree8be0d84b96e38ecb4f60f178507f8805e0b30309 /lib/sqlalchemy/testing/assertions.py
parentcaccf151f2e1b357fa2a5d37135580ce9931eec2 (diff)
downloadsqlalchemy-8a152ec391118a05ac54974d0f013cf0e99c7832.tar.gz
fix construct_params() for render_postcompile; add new API
The :meth:`.SQLCompiler.construct_params` method, as well as the :attr:`.SQLCompiler.params` accessor, will now return the exact parameters that correspond to a compiled statement that used the ``render_postcompile`` parameter to compile. Previously, the method returned a parameter structure that by itself didn't correspond to either the original parameters or the expanded ones. Passing a new dictionary of parameters to :meth:`.SQLCompiler.construct_params` for a :class:`.SQLCompiler` that was constructed with ``render_postcompile`` is now disallowed; instead, to make a new SQL string and parameter set for an alternate set of parameters, a new method :meth:`.SQLCompiler.construct_expanded_state` is added which will produce a new expanded form for the given parameter set, using the :class:`.ExpandedState` container which includes a new SQL statement and new parameter dictionary, as well as a positional parameter tuple. Fixes: #6114 Change-Id: I9874905bb90f86799b82b244d57369558b18fd93
Diffstat (limited to 'lib/sqlalchemy/testing/assertions.py')
-rw-r--r--lib/sqlalchemy/testing/assertions.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 790a72ec8..5adda0dad 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -636,10 +636,30 @@ class AssertsCompiledSQL:
eq_(cc, result, "%r != %r on dialect %r" % (cc, result, dialect))
if checkparams is not None:
- eq_(c.construct_params(params), checkparams)
+ if render_postcompile:
+ expanded_state = c.construct_expanded_state(
+ params, escape_names=False
+ )
+ eq_(expanded_state.parameters, checkparams)
+ else:
+ eq_(c.construct_params(params), checkparams)
if checkpositional is not None:
- p = c.construct_params(params, escape_names=False)
- eq_(tuple([p[x] for x in c.positiontup]), checkpositional)
+ if render_postcompile:
+ expanded_state = c.construct_expanded_state(
+ params, escape_names=False
+ )
+ eq_(
+ tuple(
+ [
+ expanded_state.parameters[x]
+ for x in expanded_state.positiontup
+ ]
+ ),
+ checkpositional,
+ )
+ else:
+ p = c.construct_params(params, escape_names=False)
+ eq_(tuple([p[x] for x in c.positiontup]), checkpositional)
if check_prefetch is not None:
eq_(c.prefetch, check_prefetch)
if check_literal_execute is not None: