OdooWiki OCA HUB

Contextvars Patch

base_contextvars folder_open OCA/server-tools open_in_new
Uncategorised License: LGPL-3

Patch Odoo threadlocals-based Environments to use contextvars instead. This is useful when the Odoo ORM must be used together with asyncio code that may lead to the execution spanning multiple threads.

This module must not be ported beyond 14.0.

auto_awesome What this module does

AI-generated from the code · Odoo 14.0

Technical patch that changes how Odoo stores its internal database environment, making it work correctly with asynchronous Python code. It adds no screens, menus or business features for end users.

This module is a technical compatibility patch, not a business feature. It replaces the way Odoo keeps track of its internal database environment (the object that gives access to records and the database) so that it is stored per asynchronous task instead of per thread. This matters when Odoo code is used together with asyncio code, where execution can move between threads.

The patch changes three internal behaviours of the Odoo environment:

  • The list of active environments is now read from a context variable, falling back to the old thread-local storage if needed.
  • The context manager used to start and stop an environment now sets and clears that context variable.
  • A reset function clears the stored environments, which can be useful when a registry is recreated inside a transaction.

It does not add any model, menu, report, button, validation rule or scheduled action. It only affects the internal Environment class of Odoo. Because it is a low-level patch, it is intended for developers and integrators, and it must not be used beyond Odoo 14.0.

Text generated by AI (DeepSeek) from reading the Odoo 14.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 1 confirmed, 8 with no information of 9 versions.

Sources · Odoo 14.0

Confirmed on 2026-11-03 in branch 14.0 of OCA/server-tools.

terminal Installation and usage

No verified information

Installation instructions, the distribution package, dependencies and configuration steps are not shown because they have not yet been verified in the module documentation for any version.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.