.. changelog::
:version: 0.9.0b2
+ .. change::
+ :tags: bug, engine
+ :tickets: 2848
+
+ The :class:`.RowProxy` object is now sortable in Python as a regular
+ tuple is; this is accomplished via ensuring tuple() conversion on
+ both sides within the ``__eq__()`` method as well as
+ the addition of a ``__lt__()`` method.
+
+ .. seealso::
+
+ :ref:`migration_2848`
+
.. change::
:tags: bug, orm
:tickets: 2833
:ticket:`2833`
+.. _migration_2848:
+
+``RowProxy`` now has tuple-sorting behavior
+-------------------------------------------
+
+The :class:`.RowProxy` object acts much like a tuple, but up until now
+would not sort as a tuple if a list of them were sorted using ``sorted()``.
+The ``__eq__()`` method now compares both sides as a tuple and also
+an ``__lt__()`` method has been added::
+
+ users.insert().execute(
+ dict(user_id=1, user_name='foo'),
+ dict(user_id=2, user_name='bar'),
+ dict(user_id=3, user_name='def'),
+ )
+
+ rows = users.select().order_by(users.c.user_name).execute().fetchall()
+
+ eq_(rows, [(2, 'bar'), (3, 'def'), (1, 'foo')])
+
+ eq_(sorted(rows), [(1, 'foo'), (2, 'bar'), (3, 'def')])
+
+:ticket:`2848`
+
.. _migration_2751:
Association Proxy SQL Expression Improvements and Fixes
__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)
c1 in row
go()
+
class ExecutionTest(fixtures.TestBase):
def test_minimal_connection_execute(self):
eq_(len(r), 1)
+ def test_sorting_in_python(self):
+ users.insert().execute(
+ dict(user_id=1, user_name='foo'),
+ dict(user_id=2, user_name='bar'),
+ dict(user_id=3, user_name='def'),
+ )
+
+ rows = users.select().order_by(users.c.user_name).execute().fetchall()
+
+ eq_(rows, [(2, 'bar'), (3, 'def'), (1, 'foo')])
+
+ eq_(sorted(rows), [(1, 'foo'), (2, 'bar'), (3, 'def')])
+
def test_column_order_with_simple_query(self):
# should return values in column definition order
users.insert().execute(user_id=1, user_name='foo')