github coleifer/peewee 4.5.0

3 hours ago

Backwards-incompatible:

  • MySQL and MariaDB connections no longer set sql_mode. Peewee had been setting PIPES_AS_CONCAT, but the param replaced the server's mode rather than adding to it, which silently disabled STRICT_TRANS_TABLES (etc). Going forward Peewee will not modify sql_mode by default and use CONCAT() rather than || for MySQL/MariaDB.
  • MySQL and MariaDB connection charset defaults to utf8mb4 instead of utf8, which is an alias for utf8mb3 and cannot store 4-byte characters.
  • A field's sequence= is now qualified with the model's Meta.schema. If the name you pass already contains a dot it is treated as fully-qualified and used as-is, so sequence='other.seq' is unaffected by Meta.schema. Also, sequence_exists() accepts a schema-qualified name.
  • SQLite BEGIN, COMMIT and ROLLBACK are issued directly on a cursor rather than through execute_sql(), so they are no longer debug-logged, do not fire query hooks and are not counted by count_queries(). This matches Postgres and MySQL.
  • atomic() and transaction() on a closed database with autoconnect=False now raise InterfaceError on Postgres and MySQL, as they already did on SQLite (and as queries do). Previously begin() opened a connection regardless of autoconnect.

Improvements:

  • Add SqliteDatabase(..., lock_type=...) to set the default locking strategy for transactions that do not specify one, e.g. lock_type='IMMEDIATE'.
  • Postgres introspection (get_tables(), get_columns(), get_indexes(), get_primary_keys(), get_foreign_keys(), get_views()) with no schema now follows the search path via current_schema() instead of assuming public, matching MySQL's DATABASE() behavior.
  • Add Runner(db, schema=...) and pwmigrate --schema for running migrations against a specific schema. The history table lives in that schema, so each schema tracks its own applied set and one set of migration files can be run against any number of schemas.
  • Add SchemaMigrator(db, schema=...), which qualifies every table name w/the given schema (or database on MySQL). Not supported for SQLite, as the table-rebuild rewrites DDL straight from sqlite_master.
  • Add websearch=True to TSVectorField.match() and Match() to parse the query using websearch_to_tsquery() (pg 11+). Accepts user input without raising (quoted phrases, or, and -negation).
  • Add Database.query_hooks, a list of callables invoked after every query with a QueryEvent named tuple (sql, params, duration, exception), on success and failure both. No timing overhead when the list is empty.
  • Add Database.after_commit(fn), which runs a callable after the outermost transaction commits. Hook is discarded on rollback and runs immediately if no transaction is active. Use for, e.g., writing a row PK to a task queue.
  • Add EnumField and IntEnumField to playhouse.fields, storing member.value and returning the member, rejecting unknown values on write and comparison. to_pydantic() maps any field with an enum_class attribute to the enum itself, so schemas validate membership.
  • Add Database.dispose() / PooledDatabase.dispose() for discarding and resetting local connection state, e.g. in a child process after fork().
  • Model.bind_ctx() and Database.bind_ctx() can be used as decorators, like the other peewee context-managers. Previously the decorator form raised TypeError: '_BoundModelsContext' object is not callable.
  • TimeField supports utc offsets like DateTimeField, parsing e.g. '11:12:13+02:00' to an aware datetime.time instead of returning str. Only sqlite stores the offset. The postgres/mysql drivers drop it on write.

View commits

karahan-tepe-man-jaguars

Don't miss a new peewee release

NewReleases is sending notifications on new releases.