Skip to content

case() with single-item dict breaks #6097

@ThiefMaster

Description

@ThiefMaster

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionsomething worked and was broken by a changesql

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions