Browse Source

Fix context from_dict() for system_scope

A previous patch[1] added "system_scope" to the context for to_dict()
but the from_dict() method was not updated. This caused the
system_scope to always be None.
This patch corrects that by adding "system_scope" to the list of
values that may need to be extracted from the context dict.

[1] https://review.opendev.org/c/openstack/oslo.context/+/530509

Change-Id: Ica23d5c4183a692de3cb65a7ad72b19f47988ca6
changes/52/800852/3
Michael Johnson 6 months ago
parent
commit
8290621b05
  1. 1
      oslo_context/context.py
  2. 4
      oslo_context/tests/test_context.py
  3. 4
      releasenotes/notes/Fix-system-scope-from_dict-29615af90723ba4d.yaml

1
oslo_context/context.py

@ -419,6 +419,7 @@ class RequestContext(object):
values.get('project_domain_name'))
kwargs.setdefault('is_admin_project',
values.get('is_admin_project', True))
kwargs.setdefault('system_scope', values.get('system_scope'))
for key in cls.FROM_DICT_EXTRA_KEYS:
kwargs.setdefault(key, values.get(key))
return cls(**kwargs)

4
oslo_context/tests/test_context.py

@ -143,7 +143,8 @@ class ContextTest(test_base.BaseTestCase):
"request_id": "request1",
"global_request_id": "req-uuid",
"resource_uuid": "instance1",
"extra_data": "foo"
"extra_data": "foo",
"system_scope": "all"
}
ctx = context.RequestContext.from_dict(dct)
self.assertEqual(dct['auth_token'], ctx.auth_token)
@ -163,6 +164,7 @@ class ContextTest(test_base.BaseTestCase):
self.assertEqual(dct['domain_name'], ctx.domain_name)
self.assertEqual(dct['user_domain_name'], ctx.user_domain_name)
self.assertEqual(dct['project_domain_name'], ctx.project_domain_name)
self.assertEqual(dct['system_scope'], ctx.system_scope)
def test_from_dict_unknown_keys(self):
dct = {

4
releasenotes/notes/Fix-system-scope-from_dict-29615af90723ba4d.yaml

@ -0,0 +1,4 @@
---
fixes:
- |
Fixes context from_dict() to properly handle system_scope.
Loading…
Cancel
Save