Skip to content

Releases: coleifer/peewee

3.16.2

21 Apr 20:18
Compare
Choose a tag to compare

Fixes a longstanding issue with thread-safety of various decorators, including atomic(), transaction(), savepoint(). The context-managers are unaffected. See #2709 for details.

View commits

3.16.1

18 Apr 17:11
Compare
Choose a tag to compare
  • Add changes required for building against Cython 3.0 and set Cython language-level to 3.
  • Ensure indexes aren't added to unindexed fields during introspection, #2691.
  • Ensure we don't redundantly select same PK in prefetch when using PREFETCH_TYPE.JOIN.
  • In Sqlite migrator, use Sqlite's builtin DROP and RENAME column facilities when possible. This can be overridden by passing legacy=True flag.

View commits

3.16.0

28 Feb 15:33
Compare
Choose a tag to compare

This release contains backwards-incompatible changes in the way Peewee
initializes connections to the underlying database driver. Previously, peewee
implemented autocommit semantics on-top of the existing DB-API transactional
workflow. Going forward, Peewee instead places the DB-API driver into
autocommit mode directly.

Why this change?

Previously, Peewee emulated autocommit behavior for top-level queries issued
outside of a transaction. This necessitated a number of checks which had to be
performed each time a query was executed, so as to ensure that we didn't end up
with uncommitted writes or, conversely, idle read transactions. By running the
underlying driver in autocommit mode, we can eliminate all these checks, since
we are already managing transactions ourselves.

Behaviorally, there should be no change -- Peewee will still treat top-level
queries outside of transactions as being autocommitted, while queries inside of
atomic() / with db: blocks are implicitly committed at the end of the
block, or rolled-back if an exception occurs.

How might this affect me?

  • If you are using the underlying database connection or cursors, e.g. via Database.connection() or Database.cursor(), your queries will now be executed in autocommit mode.
  • The commit= argument is deprecated for the cursor(), execute() and execute_sql() methods.
  • If you have a custom Database implementation (whether for a database that is not officially supported, or for the purpose of overriding default behaviors), you will want to ensure that your connections are opened in autocommit mode.

Other changes:

  • Some fixes to help with packaging in Python 3.11.
  • MySQL get_columns() implementation now returns columns in their declared order.

View commits

3.15.4

11 Nov 14:34
Compare
Choose a tag to compare
  • Raise an exception in ReconnectMixin if connection is lost while inside a transaction (if the transaction was interrupted presumably some changes were lost and explicit intervention is needed).
  • Add db.Model property to reduce boilerplate.
  • Add support for running prefetch() queries with joins instead of subqueries (this helps overcome a MySQL limitation about applying LIMITs to a subquery).
  • Add SQL AVG to whitelist to avoid coercing by default.
  • Allow arbitrary keywords in metaclass constructor, #2627
  • Add a pyproject.toml to silence warnings from newer pips when wheel package is not available.

This release has a small helper for reducing boilerplate in some cases by
exposing a base model class as an attribute of the database instance.

# old:
db = SqliteDatabase('...')

class BaseModel(Model):
    class Meta:
        database = db

class MyModel(BaseModel):
    pass

# new:
db = SqliteDatabase('...')

class MyModel(db.Model):
    pass

View commits

3.15.3

22 Sep 02:58
Compare
Choose a tag to compare
  • Add scalars() query method (complements scalar()), roughly equivalent to writing [t[0] for t in query.tuples()].
  • Small doc improvements
  • Fix and remove some flaky test assertions with Sqlite INSERT + RETURNING.
  • Fix innocuous failing Sqlite test on big-endian machines.

View commits

3.15.2

22 Sep 02:57
Compare
Choose a tag to compare
  • Fix bug where field-specific conversions were being applied to the pattern used for LIKE / ILIKE operations. Refs #2609
  • Fix possible infinite loop when accidentally invoking the __iter__ method on certain Column subclasses. Refs #2606
  • Add new helper for specifying which Model a particular selected column-like should be bound to, in queries with joins that select from multiple sources.

View commits

3.15.1

12 Jul 13:24
Compare
Choose a tag to compare
  • Fix issue introduced in Sqlite 3.39.0 regarding the propagation of column subtypes in subqueries. Affected sqlite changelog extension when used with JSON columns.
  • Fix bug where cockroachdb server version was not set when beginning a transaction on an unopened database.

View commits

3.15.0

17 Jun 12:57
Compare
Choose a tag to compare

Rollback behavior change in commit ab43376 (GH #2026). Peewee will no longer
automatically return the cursor rowcount for certain bulk-inserts. This
should only affect users of MySQL and Sqlite who relied on a bulk INSERT
returning the rowcount (as opposed to the cursor's lastrowid). The
rowcount behavior is still available chaining the as_rowcount() method:

# NOTE: this change only affects MySQL or Sqlite.
db = MySQLDatabase(...)

# Previously, bulk inserts of the following forms would return the rowcount.
query = User.insert_many(...)  # Bulk insert.
query = User.insert_from(...)  # Bulk insert (INSERT INTO .. SELECT FROM).

# Previous behavior (peewee 3.12 - 3.14.10):
# rows_inserted = query.execute()

# New behavior:
last_id = query.execute()

# To get the old behavior back:
rows_inserted = query.as_rowcount().execute()

This release contains a fix for a long-standing request to allow data-modifying
queries to support CTEs. CTEs are now supported for use with INSERT, DELETE and
UPDATE queries
- see #2152.

Additionally, this release adds better support for using the new RETURNING
syntax with Sqlite automatically. Specify returning_clause=True when
initializing your SqliteDatabase and all bulk inserts will automatically
specify a RETURNING clause, returning the newly-inserted primary keys. This
functionality requires Sqlite 3.35 or newer.

Smaller changes:

  • Add shortcuts.insert_where() helper for generating conditional INSERT with a bit less boilerplate.
  • Fix bug in test_utils.count_queres() which could erroneously include pool events such as connect/disconnect, etc.

View commits

3.14.10

07 Mar 17:19
Compare
Choose a tag to compare
  • Add shortcut for conditional insert using sub-select, see #2528
  • Add convenience left_outer_join() method to query.
  • Add selected_columns property to Select queries.
  • Add name property to Alias instances.
  • Fix regression in tests introduced by change to DataSet in 3.14.9.

View commits

3.14.9

22 Feb 15:43
Compare
Choose a tag to compare
  • Allow calling table_exists() with a model-class, refs
  • Improve is_connection_usable() method of MySQLDatabase class.
  • Better support for VIEWs with playhouse.dataset.DataSet and sqlite-web.
  • Support INSERT / ON CONFLICT in playhosue.kv for newer Sqlite.
  • Add ArrayField.contained_by() method, a corollary to contains() and the contains_any() methods.
  • Support cyclical foreign-key relationships in reflection/introspection, and also for sqlite-web.
  • Add magic methods for FTS5 field to optimize, rebuild and integrity check the full-text index.
  • Add fallbacks in setup.py in the event distutils is not available.

View commits