This release contains a number of bug fixes and one enhancement.
- Fixed #168: Incorrect caching when slicing the same query multiple times
The bug appeared when the same query instance was sliced more than once. The result of first slicing was cached and used for all subsequent slices. The correct behavior is to generate new SQL query with different LIMIT…OFFSET parameters. - Fixed #169: When py_check() returns False, Pony should truncate too large values in resulting ValueError message
Before this fix, when you tried to assign a longstr
orbytes
value and if didn’t pass the validation, the whole string was printed in the stacktrace. That could be inconvenient if the string was pretty long. Now we show only first 100 symbols and truncate the rest. - Fixed #171: AssertionError when saving changes of multiple objects
The bug appeared when there was a one-to-one relationship between two entities and both ends of this relationship were declared asOptional
. When you tried to create objects and link them in the same transaction, it could cause theAssertionError: _save_() called for object ... with incorrect status 'inserted'
- Fixed #172: Query prefetch() method should load specified lazy attributes right in the main query if possible
Before this release, the result ofprefetch()
method on a lazy attribute was a separate SQL query. That’s because the goal was not in minimizing SQL queries, but in loading all necessary data before leaving thedb_session
scope. Now Pony does prefetch smarter – it tries to minimize the number of SQL queries.
Let’s consider an example:from pony.orm import * db = Database() class Post(db.Entity): title = Required(str, 128) text = Required(LongStr) db.bind('sqlite', ':memory:') db.generate_mapping(create_tables=True) sql_debug(True) with db_session: posts = Post.select().prefetch(Post.text)[:]
In this example the
text
attribute is declared as the lazy string type. Before this release Pony always loaded lazy attributes using a separate SQL query. Now, if you pass such a lazy attribute to theprefetch()
method, Pony will retrieve this field in the main SQL query:SELECT "p"."id", "p"."title", "p"."text" FROM "Post" "p"
- Fixed #176: Autostripped strings are not validated correctly for Required attributes
The bug was that Pony automatically striped attribute value after validation, not before it. So, if we had aRequired
attribute and tried to assign some value which contained only spaces, Pony would through theValueError: Attribute ... is required
. Now Pony first strips the value and then does the validation.
To install the updated version use the following command:
pip install --upgrade pony