New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect caching when slicing the same query multiple times #168

Closed
andreymal opened this Issue Feb 26, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@andreymal

andreymal commented Feb 26, 2016

from pony.orm import *

db = Database()

class TestPost(db.Entity):
    name = Required(str, 128, autostrip=False)

db.bind('sqlite', ':memory:')
db.generate_mapping(create_tables=True)
# sql_debug(True)

with db_session:
    for i in range(1, 101):
        post = TestPost(name='post {}'.format(i))
        post.flush()

with db_session:
    query = TestPost.select()
    print(query[30:33])  # [31, 32, 33]

with db_session:
    query = TestPost.select()
    len(query)  # 100
    # Offopic: how about to make query.__len__() equivalent of query.count()?
    print(query[30:33])  # [1, 2, ..., 99, 100]???

with db_session:
    query = TestPost.select()
    print(query[95:98])  # [96, 97, 98]
    print(query[30:33])  # [96, 97, 98]???

@kozlovsky kozlovsky added the bug label Feb 26, 2016

@kozlovsky kozlovsky self-assigned this Feb 26, 2016

@kozlovsky kozlovsky added this to the 0.6.5 milestone Feb 27, 2016

@kozlovsky kozlovsky closed this in e63ba66 Feb 27, 2016

@kozlovsky

This comment has been minimized.

Show comment
Hide comment
@kozlovsky

kozlovsky Feb 27, 2016

Member

Fixed. Regarding making query.__len__() equivalent of query.count(): currect behavior of query.__len__() is more efficient if you need to do iteration over resulted objects, one less query is sent to the database. Also, count() does not guarantee that the number will actually match the number of objects, because most databases does not provide serializable isolation level by default, and another transaction can insert/delete rows after the count is executed..

Member

kozlovsky commented Feb 27, 2016

Fixed. Regarding making query.__len__() equivalent of query.count(): currect behavior of query.__len__() is more efficient if you need to do iteration over resulted objects, one less query is sent to the database. Also, count() does not guarantee that the number will actually match the number of objects, because most databases does not provide serializable isolation level by default, and another transaction can insert/delete rows after the count is executed..

@socketpair

This comment has been minimized.

Show comment
Hide comment
@socketpair

socketpair Mar 21, 2016

Так и не понял в чём именно баг (когда проявляется)

socketpair commented Mar 21, 2016

Так и не понял в чём именно баг (когда проявляется)

@kozlovsky

This comment has been minimized.

Show comment
Hide comment
@kozlovsky

kozlovsky Mar 22, 2016

Member

@socketpair the bug manifested itself when a different slicing was applied to the same query instance. The result of first slicing was cached and used for all subsequent slices. The correct behavior is to issue another SQL query with different LIMIT...OFFSET parameters.

Member

kozlovsky commented Mar 22, 2016

@socketpair the bug manifested itself when a different slicing was applied to the same query instance. The result of first slicing was cached and used for all subsequent slices. The correct behavior is to issue another SQL query with different LIMIT...OFFSET parameters.

@kozlovsky kozlovsky changed the title from Too many caching in core.Query? to Incorrect caching when slicing the same query multiple times Apr 4, 2016

kozlovsky added a commit that referenced this issue Apr 4, 2016

Pony ORM Release 0.6.5 (2016-04-04)
# Improvements

* Fixes #172: Query prefetch() method should load specified lazy attributes right in the main query if possible

# Bugfixes

* Fixes #168: Incorrect caching when slicing the same query multiple times
* Fixes #169: When py_check() returns False, Pony should truncate too large values in resulting ValueError message
* Fixes #171: AssertionError when saving changes of multiple objects
* Fixes #176: Autostripped strings are not validated correctly for Required attributes

See blog post for more detailed information: https://blog.ponyorm.com/2016/04/04/pony-orm-release-0-6-5/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment