This PR contains the following updates:
Release Notes
coleifer/peewee (peewee)
Compare Source
- Unfortunately, the new JSONField did not play nice w/MySQL when query was
generated before a conn was opened. We were trying to do some introspection
on the server version, but I've decided instead to make mariadb= be a
database param, per @alisonatwork's suggestion, with the default being
"MySQL" flavored JSON. Refs #3053
JSONField containment (contains, contained_by) no longer wraps its
argument in CAST / JSON_COMPACT on MySQL/MariaDB, #3053.
View commits
Compare Source
- Ensure new JSONField can be inherited, #3052
View commits
Compare Source
- Add
BaseQuery.aexecute() - an async twin of execute() available on all
query types, executing through the query's bound async database:
await User.select().aexecute(), await user.tweets.aexecute(). Returns
exactly what execute() returns, including result rows for DML with
RETURNING. Queries remain non-awaitable; this is an ordinary coroutine
method and the only async method on queries.
- Add async model methods to
playhouse.pwasyncio using "a"-prefixed coroutine
counterparts of the row-level Model methods (acreate, aget,
aget_or_none, aget_by_id, aget_or_create, aset_by_id,
adelete_by_id, abulk_create, abulk_update, asave,
adelete_instance), available via the new AsyncModel /
AsyncModelMixin classes. Each is a thin delegation through the greenlet
bridge, so behavior is identical to the synchronous implementation.
Note: the Model property of async databases now returns a base class
that includes these methods - relevant only if you introspect the base
class of db.Model subclasses.
- Add
afetch() for explicit, awaitable lazy foreign-key resolution:
user = await tweet.afetch(Tweet.user). Already-loaded relations (via
join or prefetch) return immediately without a query.
- Add
db.first(query, n=1) async helper.
MissingGreenletBridge errors now include a hint describing the async
APIs to use.
- The asyncio extension is no longer considered preliminary - the async
APIs documented in the docs
are stable. The asyncio stress test now also runs in CI.
View commits
Compare Source
- Fixes for
playhouse.pwasyncio: report correct UPDATE / DELETE rowcounts on
asyncpg, roll back open transactions when connections are returned to the
pool, raise instead of deadlocking when querying during iterate(), and
detect the MySQL / MariaDB server version.
- Additional
playhouse.pwasyncio fixes: a second iterate() on a busy
connection raises instead of deadlocking, asyncpg exceptions are translated
to peewee exception types, registered aggregates / collations / window
functions / extensions and timeout are applied to async SQLite
connections, :memory: databases use a single connection, atomic()
accepts transaction arguments (e.g. lock_type), postgres connection URLs
and isolation_level are supported, %% in raw SQL is unescaped, and
attempting a query outside the greenlet bridge no longer emits "never
awaited" warnings.
- Fixes for
playhouse.pydantic_utils: JSON fields validate as Any (now
including the sqlite_ext JSONField), foreign keys may be included /
excluded by field name or column name, server-side defaults like
SQL('CURRENT_TIMESTAMP') are no longer emitted as schema defaults, and
relationships keys are validated.
- Add a new cross-backend
JSONField to core that provides basic operations
and also more consistent behavior when reading data. By default the new core
JSONField treats extracted values as JSON, which is generally the correct
thing, but "text-mode" is available as a chained .as_text() method. See
docs.
May eventually replace the backend-specific implementations with subclasses
that inherit semantics of this new field.
Note: playhouse.mysql_ext.JSONField is now the core field. The old
json_dumps / json_loads arguments are renamed dumps / loads, the
extract() method is removed (use item-access or path()), and MySQL
tables are now created with JSON columns rather than TEXT.
- Eliminate use of deprecated params when connecting to MySQL databases, thanks
to @abulgher, #3050.
- Using
fromisoformat() ended up causing previously-unconverted strings (Ymd)
to be converted in some cases, e.g. formatting a datetime as a str (#3051).
The change I made to address this is to make explicit casts on function calls
not attempt any heuristic python-value conversion. This makes it more natural
to call fn.whatever().cast('text') and you predictably get text out.
View commits
Compare Source
- Add new methods to the postgres
BinaryJSONField: helpers for in-place
modifications (set, replace, insert, append, update).
- Also add json-path helpers to the postgres
BinaryJSONField (path_exists,
path_match, path_query, path_query_array, path_query_first).
- Quote path elements in SQLite's JSON field.
- Better and faster parsing of formatted date/times. Use the stdlib
fromisoformat as a first attempt since it's faster and more robust.
- Ensure
db.connection_context() can be nested cleanly, #3046.
- Fix potential deadlock in
pool.close_all and pool.manual_close, #3047.
- Restore whitespace stripping in
FixedCharField, #3048.
View commits
Compare Source
- Fix bug where
db_value() may not get called in subclasses of Postgres
JSONField / BinaryJSONField, refs #3044.
- Fix bug where indexes for table may be defined on multiple schema, #3043.
- Always fall-through to base exception class if exception is not recognized in
DB drivers. This simplifies checking driver-specific subclasses of standard
DB-API exceptions.
View commits
Compare Source
- Fix SQL generation for partial indexes with nulls (not) distinct clause.
- Raise an
ImproperlyConfigured if pg driver unavailable at model
definition-time when field db-hooks are used, rather than AttributeError.
View commits
Compare Source
- Refactor test suite - this was a mechanical refactor, just moving things
around and trying to group things more clearly. Also added new tests covering
some gaps.
- Expand multi-value types to include generator expressions, so you can write
stuff like .in(a for a in iterable if cond).
- Ensure quotes embedded in entity names are escaped.
- Improved specification of
FOR UPDATE clauses.
- Fix for negative values in
paginate() method.
- Fix for newer MySQL server versions in feature detection code.
- More robust handling of unusual aliases / invalid attr names in cursor
wrapper.
- Better handling of duplicated column names in cursor wrapper implementations.
- Improve performance of ModelCursorWrapper when reconstructing model instance
graphs after multi-table selects.
- If only psycopg3 is installed, use it by default (#3036)
View commits
Compare Source
- Remove all Python 2.x compatibility code.
- Add streaming result cursors to pwasyncio module via
db.iterate(query).
- Better serialization and deserialization of datetimes and binary data in the
DataSet module. Previously binary data was encoded as base64, going forward
hex is the new default. For base64 specify base64_bytes=True.
- Improvements to Postgres
BinaryJSONField, support atomic removal of
sub-elements, as well as alternate helper for extracting sub-elements and
querying array length.
- Pydantic integration
View commits
Compare Source
- Ensure
gr_context is set on greenlet in greenlet_spawn so that
contextvars will be operable in sync handlers.
- Removed
SqliteExtDatabase (it basically served no purpose in 4.0). Use
SqliteDatabase instead.
- Moved driver and extension-specific pooled implementations into the
corresponding extension module rather than putting all into playhouse.pool.
- Restore custom
dumps option for postgres JSON fields.
- Major docs rewrite / reorganization.
View commits
Compare Source
- Adds preliminary support for
asyncio via a new playhouse extension. See
the documentation
for details.
PostgresqlDatabase can use psycopg (psycopg3) if it is installed. If both
psycopg2 and psycopg3 are installed, Peewee will prefer psycopg2, but this
can be controlled by specifying prefer_psycopg3=True in the constructor.
Same applies to PostgresqlExtDatabase.
Psycopg3Database class has been moved to playhouse.postgres_ext and is
now just a thin wrapper around PostgresqlExtDatabase.
- Postgres JSON operations no longer dump and try to do minimal casts, instead
relying on the driver-provided Json() wrapper(s).
- Adds new
ISODateTimeField for Sqlite that encodes datetimes in ISO format
(more friendly when db is shared with other tools), and also properly reads
back UTC offset info.
- Remove
playhouse.sqlite_ext.ClosureTable implementation.
- Add a
Model.dirty_field_names attribute that is safe for membership
testing, since testing x in dirty_fields returns True if one or more field
exists due to operator overloads returning a truthy Expression object.
Refs #3028.
- Removal of Cython
_sqlite_ext extension. The C implementations of the FTS
rank functions are moved to sqlite_udf. Most of the remaining functionality
is moved to playhouse.cysqlite_ext which supports it natively.
Migrating CSqliteExtDatabase usage:
You can either use sqlite_ext.SqliteExtDatabase or try the new
cysqlite_ext.CySqliteDatabase if you want all the old functionality and are
willing to try a new driver.
View commits
Configuration
📅 Schedule: (UTC)
- Branch creation
- At any time (no schedule defined)
- Automerge
- At any time (no schedule defined)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.
Uh oh!
There was an error while loading. Please reload this page.
This PR contains the following updates:
~3.19.0→~4.1.0Release Notes
coleifer/peewee (peewee)
v4.1.0Compare Source
generated before a conn was opened. We were trying to do some introspection
on the server version, but I've decided instead to make
mariadb=be adatabase param, per @alisonatwork's suggestion, with the default being
"MySQL" flavored JSON. Refs #3053
JSONFieldcontainment (contains,contained_by) no longer wraps itsargument in
CAST/JSON_COMPACTon MySQL/MariaDB, #3053.View commits
v4.0.9Compare Source
View commits
v4.0.8Compare Source
BaseQuery.aexecute()- an async twin ofexecute()available on allquery types, executing through the query's bound async database:
await User.select().aexecute(),await user.tweets.aexecute(). Returnsexactly what
execute()returns, including result rows for DML withRETURNING. Queries remain non-awaitable; this is an ordinary coroutinemethod and the only async method on queries.
playhouse.pwasynciousing "a"-prefixed coroutinecounterparts of the row-level
Modelmethods (acreate,aget,aget_or_none,aget_by_id,aget_or_create,aset_by_id,adelete_by_id,abulk_create,abulk_update,asave,adelete_instance), available via the newAsyncModel/AsyncModelMixinclasses. Each is a thin delegation through the greenletbridge, so behavior is identical to the synchronous implementation.
Note: the
Modelproperty of async databases now returns a base classthat includes these methods - relevant only if you introspect the base
class of
db.Modelsubclasses.afetch()for explicit, awaitable lazy foreign-key resolution:user = await tweet.afetch(Tweet.user). Already-loaded relations (viajoin or prefetch) return immediately without a query.
db.first(query, n=1)async helper.MissingGreenletBridgeerrors now include a hint describing the asyncAPIs to use.
APIs documented in the docs
are stable. The asyncio stress test now also runs in CI.
View commits
v4.0.7Compare Source
playhouse.pwasyncio: report correct UPDATE / DELETE rowcounts onasyncpg, roll back open transactions when connections are returned to the
pool, raise instead of deadlocking when querying during
iterate(), anddetect the MySQL / MariaDB server version.
playhouse.pwasynciofixes: a seconditerate()on a busyconnection raises instead of deadlocking, asyncpg exceptions are translated
to peewee exception types, registered aggregates / collations / window
functions / extensions and
timeoutare applied to async SQLiteconnections,
:memory:databases use a single connection,atomic()accepts transaction arguments (e.g.
lock_type), postgres connection URLsand
isolation_levelare supported,%%in raw SQL is unescaped, andattempting a query outside the greenlet bridge no longer emits "never
awaited" warnings.
playhouse.pydantic_utils: JSON fields validate asAny(nowincluding the sqlite_ext
JSONField), foreign keys may be included /excluded by field name or column name, server-side defaults like
SQL('CURRENT_TIMESTAMP')are no longer emitted as schema defaults, andrelationshipskeys are validated.JSONFieldto core that provides basic operationsand also more consistent behavior when reading data. By default the new core
JSONField treats extracted values as JSON, which is generally the correct
thing, but "text-mode" is available as a chained
.as_text()method. Seedocs.
May eventually replace the backend-specific implementations with subclasses
that inherit semantics of this new field.
Note:
playhouse.mysql_ext.JSONFieldis now the core field. The oldjson_dumps/json_loadsarguments are renameddumps/loads, theextract()method is removed (use item-access orpath()), and MySQLtables are now created with
JSONcolumns rather thanTEXT.to @abulgher, #3050.
fromisoformat()ended up causing previously-unconverted strings (Ymd)to be converted in some cases, e.g. formatting a datetime as a str (#3051).
The change I made to address this is to make explicit casts on function calls
not attempt any heuristic python-value conversion. This makes it more natural
to call
fn.whatever().cast('text')and you predictably get text out.View commits
v4.0.6Compare Source
BinaryJSONField: helpers for in-placemodifications (
set,replace,insert,append,update).BinaryJSONField(path_exists,path_match,path_query,path_query_array,path_query_first).fromisoformatas a first attempt since it's faster and more robust.db.connection_context()can be nested cleanly, #3046.pool.close_allandpool.manual_close, #3047.FixedCharField, #3048.View commits
v4.0.5Compare Source
db_value()may not get called in subclasses of PostgresJSONField / BinaryJSONField, refs #3044.
DB drivers. This simplifies checking driver-specific subclasses of standard
DB-API exceptions.
View commits
v4.0.4Compare Source
ImproperlyConfiguredif pg driver unavailable at modeldefinition-time when field db-hooks are used, rather than
AttributeError.View commits
v4.0.3Compare Source
around and trying to group things more clearly. Also added new tests covering
some gaps.
stuff like
.in(a for a in iterable if cond).FOR UPDATEclauses.paginate()method.wrapper.
graphs after multi-table selects.
View commits
v4.0.2Compare Source
db.iterate(query).DataSet module. Previously binary data was encoded as base64, going forward
hex is the new default. For base64 specify
base64_bytes=True.BinaryJSONField, support atomic removal ofsub-elements, as well as alternate helper for extracting sub-elements and
querying array length.
View commits
v4.0.1Compare Source
gr_contextis set on greenlet ingreenlet_spawnso thatcontextvars will be operable in sync handlers.
SqliteExtDatabase(it basically served no purpose in 4.0). UseSqliteDatabaseinstead.corresponding extension module rather than putting all into
playhouse.pool.dumpsoption for postgres JSON fields.View commits
v4.0.0Compare Source
asynciovia a new playhouse extension. Seethe documentation
for details.
PostgresqlDatabasecan usepsycopg(psycopg3) if it is installed. If bothpsycopg2 and psycopg3 are installed, Peewee will prefer psycopg2, but this
can be controlled by specifying
prefer_psycopg3=Truein the constructor.Same applies to
PostgresqlExtDatabase.Psycopg3Databaseclass has been moved toplayhouse.postgres_extand isnow just a thin wrapper around
PostgresqlExtDatabase.relying on the driver-provided
Json()wrapper(s).ISODateTimeFieldfor Sqlite that encodes datetimes in ISO format(more friendly when db is shared with other tools), and also properly reads
back UTC offset info.
playhouse.sqlite_ext.ClosureTableimplementation.Model.dirty_field_namesattribute that is safe for membershiptesting, since testing
x in dirty_fieldsreturns True if one or more fieldexists due to operator overloads returning a truthy Expression object.
Refs #3028.
_sqlite_extextension. The C implementations of the FTSrank functions are moved to
sqlite_udf. Most of the remaining functionalityis moved to
playhouse.cysqlite_extwhich supports it natively.Migrating
CSqliteExtDatabaseusage:You can either use
sqlite_ext.SqliteExtDatabaseor try the newcysqlite_ext.CySqliteDatabaseif you want all the old functionality and arewilling to try a new driver.
View commits
Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.