case() with a not_(...) condition throws exception

Issue #1661 resolved
Former user created an issue

The code:

case([ (not_(foo.c.x), 42) ])

Expected: statement like CASE WHEN NOT foo.x THEN 42 END

Observed this exception instead:

Traceback (most recent call last):
  File "/tmp/testcase.py", line 10, in <module>
    (not_(foo.c.x), 42),
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sqlalchemy/sql/expression.py", line 466, in case
    return _Case(whens, value=value, else_=else_)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/sqlalchemy/sql/expression.py", line 2205, in __init__
    whenlist = [_literal_as_binds(r)) for (c, r) in whens]((_no_literals(c).self_group(),)
TypeError: self_group() takes exactly 2 arguments (1 given)

Minimal test case is attached.

Versions: OS X 10.5, Python 2.6.4 from MacPorts, SQLAlchemy 0.5.8.

For what it's worth, my uninformed guess would be that _UnaryExpression.self_group needs to default against=None (like I see a few other places doing).

(SQLAlchemy rocks. Thanks!)

Comments (6)

  1. Log in to comment