Skip to content

RowProxy.__eq__() throws unexpected TypeError #2924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sqlalchemy-bot opened this issue Jan 28, 2014 · 5 comments
Closed

RowProxy.__eq__() throws unexpected TypeError #2924

sqlalchemy-bot opened this issue Jan 28, 2014 · 5 comments
Labels
bug Something isn't working engine engines, connections, transactions, isolation levels, execution options high priority
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Anonymous

(original reporter: elic) As of 0.9, comparing a sqlalchemy.engine.result.RowProxy against any non-iterable (e.g. doing RowProxy(...) == 123) results in a TypeError, rather 0.8's behavior where it would return False. This breaks the normal python behavior where different types can be compared for equality (e.g. assert {} != 5). I think this was caused by rev 02f21ff.

A simple fix would probably be wrapping the existing RowProxy.__eq__() in a try/except that catches TypeError, and returns False; though limiting try/except to just the tuple(other) call would prevent it from masking other unrelated TypeErrors.

That changeset also causes RowProxy() < 5 return a TypeError, but that part seems fine to me, since Python 3 made that an expected behavior of __lt__() and friends (e.g. None < 1 now returns TypeError("unorderable types")).

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

or just throwing an isinstance() in there.

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • added labels: high priority

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.9.xx" to "0.9.2"

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

check out how I did this in d4c908d, I've added test coverage ensuring that all equality operators (==, !=, <, >, <=, >=) should behave identically to that of a tuple. reopen if I got it wrong, thanks!

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added high priority bug Something isn't working engine engines, connections, transactions, isolation levels, execution options labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.9.2 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working engine engines, connections, transactions, isolation levels, execution options high priority
Projects
None yet
Development

No branches or pull requests

1 participant