perfect_python_project
perfect_python_project copied to clipboard
Encode/Databases 0.8.0 breaks fastapi-complete tests
According to 0.8.0 release notes:
This release improves isolation of connections and transactions across concurrent tasks:
- Database connections are now task-local and are not inherited by child tasks
- The @db.transaction decorator uses the calling task's connection
- Each new task uses a new connection unless a connection is explicitly provided
These changes improve the consistency of behavior and fix bugs where connections and transactions were not properly isolated such as: https://github.com/encode/databases/issues/123, https://github.com/encode/databases/issues/125, https://github.com/encode/databases/issues/134, https://github.com/encode/databases/issues/155, https://github.com/encode/databases/issues/424, and https://github.com/encode/databases/issues/452.
In most cases, these changes should not be breaking. However, if using an open transaction across tasks, the active connection (db.connection()) now needs to be explicitly passed to each task. See the new documentation for an example.
Those changes break the app
fixture which wraps the app with a db.transaction(force_rollback=True):
to roll back all changes made during testing.