Slicing of Query instances can return inconsistent types if negative
stop/start values are used.

The below patch to tes/orm/query.py demonstrates the issue. When
slices with negative stop/start values are used, a list type is
returned. When positive values are used, a Query instance is returned.
Is this a bug?

If this is a bug, I might be able to fix it, but I'm not sure what a
slice should return. Should a list be returned from a slice operation,
or should a Query instance be returned?


Index: orm/query.py
===================================================================
--- orm/query.py        (revision 3743)
+++ orm/query.py        (working copy)
@@ -5,6 +5,7 @@
 from sqlalchemy.sql import compiler
 from sqlalchemy.engine import default
 from sqlalchemy.orm import *
+from sqlalchemy.orm import query
 from testlib import *
 from testlib import engines
 from testlib.fixtures import *
@@ -268,6 +269,11 @@
     def test_basic(self):
         assert [User(id=7), User(id=8), User(id=9),User(id=10)] ==
create_session().query(User).all()

+    def test_negative_slices(self):
+        s = create_session()
+        assert type(s.query(Address).filter(Address.user_id==8)[1:3])
is query.Query
+        assert type(s.query(Address).filter(Address.user_id==8)
[-2:-1]) is query.Query
+
     @testing.fails_on('maxdb')
     def test_limit(self):
         assert [User(id=8), User(id=9)] ==
create_session().query(User).limit(2).offset(1).all()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to