Reference == Int works to build join condition, but Int == Reference fails
Bug #244769 reported by
Stuart Bishop
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
New
|
Undecided
|
Unassigned |
Bug Description
Where Foo.id is an integer primary key and Bar.foo is a Reference to Foo.id, the expression Bar.foo == Foo.id works as expected but Foo.id == Bar.foo raises a TypeError.
To post a comment you must log in.
This is due to choice of the __eq__() method. For "Bar.foo == Foo.id", Reference.__eq__() is executed which generates a correct expression object.
For "Foo.id == Bar.foo", Comparable.__eq__() is executed, which tries to convert Bar.foo (a Reference object) to an integer, which gives a TypeError. Perhaps some of these rich comparison methods should be returning NotImplemented instead? That would allow Reference.__eq__() to have a go in this second case.