diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-12-21 17:35:12 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-12-21 21:50:55 -0500 |
commit | c495769751e8b19d54fb92388ced587b5d13b85d (patch) | |
tree | b0a4415469bb608f78fbcdfb4b240ecc7f54b37b /test/sql/test_query.py | |
parent | 41f47fb72c5e9382b92f1c66f54771788be648ad (diff) | |
download | sqlalchemy-c495769751e8b19d54fb92388ced587b5d13b85d.tar.gz |
Maintain compiled_params / replacement_expressions within expanding IN
Fixed issue in "expanding IN" feature where using the same bound parameter
name more than once in a query would lead to a KeyError within the process
of rewriting the parameters in the query.
Fixes: #4394
Change-Id: Ibcadce9fefbcb060266d9447c2044ee6efeccf5a
Diffstat (limited to 'test/sql/test_query.py')
-rw-r--r-- | test/sql/test_query.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 971374eb9..175b69c4f 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -529,6 +529,41 @@ class QueryTest(fixtures.TestBase): [(8, 'fred'), (9, 'ed')] ) + def test_expanding_in_repeated(self): + testing.db.execute( + users.insert(), + [ + dict(user_id=7, user_name='jack'), + dict(user_id=8, user_name='fred'), + dict(user_id=9, user_name='ed') + ] + ) + + with testing.db.connect() as conn: + stmt = select([users]).where( + users.c.user_name.in_( + bindparam('uname', expanding=True) + ) | users.c.user_name.in_(bindparam('uname2', expanding=True)) + ).where(users.c.user_id == 8) + stmt = stmt.union( + select([users]).where( + users.c.user_name.in_( + bindparam('uname', expanding=True) + ) | users.c.user_name.in_( + bindparam('uname2', expanding=True)) + ).where(users.c.user_id == 9) + ).order_by(stmt.c.user_id) + + eq_( + conn.execute( + stmt, + { + "uname": ['jack', 'fred'], + "uname2": ['ed'], "userid": [8, 9]} + ).fetchall(), + [(8, 'fred'), (9, 'ed')] + ) + @testing.requires.tuple_in def test_expanding_in_composite(self): testing.db.execute( |