The `oslo.context` library is a core OpenStack component providing helpers to manage and maintain useful information about a request context. This context is typically populated within a WSGI pipeline and utilized by various modules, such as `oslo.log`, for consistent data access throughout a request's lifecycle. The library is currently at version 6.3.0 and follows the OpenStack release cadence.
pip install oslo.contextVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `RequestContext` object, make it available globally within the current thread using `make_current()`, and retrieve it with `get_current()`. It also shows how to create a specialized admin context. For real-world applications, `RequestContext` is typically initialized by WSGI middleware and automatically managed.
Migrate from using `tenant` to `project_id` or `project_name` when initializing or accessing context information. Review your `RequestContext` instantiations and update arguments accordingly.
Always use keyword arguments when initializing `RequestContext` to ensure clarity and forward compatibility (e.g., `RequestContext(user_id='...', project_id='...')` instead of `RequestContext('...', '...')`).If your application explicitly uses `get_logging_values` and expects the full `auth_token`, be aware of this change. For non-logging purposes, access `context.auth_token` directly from your `RequestContext` instance.
For multi-threaded or asynchronous environments, ensure that the `RequestContext` is explicitly passed or re-established in the new thread/task context. Libraries like `oslo.privsep` and `oslo.middleware` handle this for specific use cases [8, 18].
Migrate from using 'tenant' to 'project_id' or 'project_name' when initializing or accessing context information. For example, replace `RequestContext(tenant=...)` with `RequestContext(project_id=...)` or `RequestContext(project_name=...)`.
For multi-threaded or asynchronous environments, ensure that the `RequestContext` is explicitly passed or re-established within the new thread/task context. This often involves making the context available to the new execution unit, for instance, by passing the context object as an argument.
Ensure that the desired attribute is properly initialized when the `RequestContext` is created or updated. If the error occurs after calling `get_current()`, add a check to ensure a valid context object was returned before attempting to access its attributes, e.g., `context = oslo_context.context.get_current(); if context: print(context.attribute_name)`.
No dependency data recorded yet.