-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
case() with single-item dict breaks #6097
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingregressionsomething worked and was broken by a changesomething worked and was broken by a changesql
Milestone
Description
Describe the bug
case() with a single-item dict fails; this used to work in 1.3
To Reproduce
from sqlalchemy import *
from sqlalchemy.orm import *
Base = declarative_base()
class Test(Base):
__tablename__ = 'test'
id = Column(Integer, primary_key=True)
foo = Column(String)
print(case({'a': 'aa', 'b': 'bb'}, else_='c', value=Test.foo))
print()
print(case({'a': 'aa'}, else_='c', value=Test.foo))Error
$ python /tmp/satest.py
CASE test.foo WHEN :param_1 THEN :param_2 ELSE :param_3 END
Traceback (most recent call last):
File "/tmp/satest.py", line 16, in <module>
print(case({'a': 'aa'}, else_='c', value=Test.foo))
File "<string>", line 2, in case
File "/home/adrian/dev/indico/py3/env/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 2755, in __init__
whenlist = [
File "/home/adrian/dev/indico/py3/env/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 2764, in <listcomp>
for (c, r) in whens
ValueError: not enough values to unpack (expected 2, got 1)
Versions.
- OS: Linux
- Python: 3.9.1
- SQLAlchemy: 1.4.1
- Database: n/a
- DBAPI: n/a
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingregressionsomething worked and was broken by a changesomething worked and was broken by a changesql