psycopg/psycopg2 — pull request #10 by cjw296 (2014-02-12 08:41:17+00:00)
Title: Provide a stable and consistent sort order for Range objects.

This matches postgres server-side behaviour and helps client applications that need to sort based on the primary key of tables where the primary key is or contains a range.

The specific case I hit this was here:

File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/session.py", line 1818, in flush
self._flush(objects)
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/session.py", line 1936, in _flush
transaction.rollback(_capture_exception=True)
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/util/langhelpers.py", line 58, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/session.py", line 1900, in _flush
flush_context.execute()
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 372, in execute
rec.execute(self)
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 525, in execute
uow
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/persistence.py", line 45, in save_obj
uowtransaction)
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/persistence.py", line 140, in _organize_states_for_save
states):
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/persistence.py", line 767, in _connections_for_states
for state in _sort_states(states):
File "/Users/chris/buildout-eggs/SQLAlchemy-0.8.2-py2.7-macosx-10.5-x86_64.egg/sqlalchemy/orm/persistence.py", line 792, in _sort_states
sorted(persistent, key=lambda q: q.key[1])
File "/Users/chris/buildout-eggs/psycopg2-2.5.1-py2.7-macosx-10.5-x86_64.egg/psycopg2/_range.py", line 138, in __lt__
'Range objects cannot be ordered; please refer to the PostgreSQL'

Mail thread here:
https://groups.google.com/forum/#!searchin/sqlalchemy/range$20objects$20cannot$20be$20ordered/sqlalchemy/mWbr-Tw4wvU/QXFYH2rRgFsJ