Skip to content

RowProxy don't get sorted as expected #2848

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Anonymous

If one uses raw queries like this:

res = list(session.execute("SELECT a,b FROM my_subscription"))

then we see (by printing) that res is [13209L), (1L, 7057L), (2L, 410L), (10L, 3L), (6L, 10L)]((0L,)

But these aren't tuples, so when we try to sort() that list (or use sorted() on it), records just get weirdly mixed up.

I guess RowProxy objects should have the same behaviour as tuples when it comes to sorting, or else they should display themselves as objects instead of tuples, to avoid confusing unexperienced users.

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Oct 21, 2013

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

patch:

diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index 0e23165..93c7d3b 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -125,8 +125,11 @@ class RowProxy(BaseRowProxy):
 
     __hash__ = None
 
+    def __lt__(self, other):
+        return tuple(self) < tuple(other)
+
     def __eq__(self, other):
-        return other is self or other == tuple(self)
+        return other is self or tuple(other) == tuple(self)
 
     def __ne__(self, other):
         return not self.__eq__(other)
sqlalchemy-bot

sqlalchemy-bot commented on Oct 21, 2013

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • removed labels: cextensions
  • added labels: high priority, engine
  • set milestone to "0.9.0"
sqlalchemy-bot

sqlalchemy-bot commented on Nov 19, 2013

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

02f21ff

sqlalchemy-bot

sqlalchemy-bot commented on Nov 19, 2013

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
added
bugSomething isn't working
engineengines, connections, transactions, isolation levels, execution options
on Nov 27, 2018
added this to the 0.9.0 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingengineengines, connections, transactions, isolation levels, execution optionshigh priority

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          RowProxy don't get sorted as expected · Issue #2848 · sqlalchemy/sqlalchemy