this is how its designed to work at the moment.  if the slices are  
negative, it evaulates the query fully and returns the slice against  
the actual list.   complicating matters more, we just had a feature  
request today to wrap the query in a subquery if additional criterion,  
such as order by, are applied *after* the LIMIT/OFFSET, which would  
make potential solutions (like holding onto the negative-valued slice  
and applying it later at evaluation time) impossible.

On Nov 6, 2007, at 9:27 AM, Simon Wittber wrote:

>
> 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 sqlalchemy@googlegroups.com
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