Reference == Int works to build join condition, but Int == Reference fails

Bug #244769 reported by Stuart Bishop
10
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.

Revision history for this message
Stuart Bishop (stub) wrote :
Revision history for this message
James Henstridge (jamesh) wrote :

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.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

As discussed in #627137 (which is probably a duplicate and should be marked as such), Foo.id == Bar.foo feels a bit strange. I see no clarity wins when compared to Foo.id == Bar.foo_id. Bar.foo == Foo might be nice, though.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.