ColumnCollection doesn't follow dictionary semantics

Issue #606 resolved
Former user created an issue

Everytime you try something like:

t = model.metadata.tables'test' print 'name' in t.c

ALWAYS returns false. The error was in the contains method of the sql.ColumnCollection class. A patch is attached, showing the code difference.

The file is lib/sqlalchemy/sql.py

Nicholas Amorim

Comments (8)

  1. Mike Bayer repo owner

    OK...actually, thats not the point of the __contains__() method at the moment. it wasnt intended to be used with strings, its intended to be used with Column objects. thats why the 3 line comment and Set is there, although Column should probably implement hash() and cmp() to eliminate the need for that (eq() already is modified in such a way as to not work for dictionaries).

    however since the ColumnCollection is acting like a dict, the contains should be decoupled from the contains_column() method and all the relevant ORM code changed to not use "in" (hence a "major" change).

  2. Former user Account Deleted

    Even actiing like a dict, why not support "in" ?

    A normal dict supports it with keys.

    foo = {"bar" : "test"} "bar" in foo True

  3. Mike Bayer repo owner

    yes, thats the point of the ticket, which is still open until this change is made. the current internal usage of "in" on this object is in conflict with dictionary semantics.

  4. Log in to comment