Skip to content

Commit 15e649c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Replace context decorators with context managers" into stable/yoga
2 parents 995c465 + c3fb31b commit 15e649c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

neutron/objects/db/api.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# TODO(ihrachys): cover the module with functional tests targeting supported
1414
# backends
1515

16+
from neutron_lib.db import api as db_api
1617
from neutron_lib.db import model_query
1718
from neutron_lib import exceptions as n_exc
1819
from neutron_lib.objects import utils as obj_utils
@@ -31,16 +32,18 @@ def _get_filter_query(obj_cls, context, query_field=None, query_limit=None,
3132

3233

3334
def get_object(obj_cls, context, **kwargs):
34-
return _get_filter_query(obj_cls, context, **kwargs).first()
35+
with db_api.CONTEXT_READER.using(context):
36+
return _get_filter_query(obj_cls, context, **kwargs).first()
3537

3638

3739
def count(obj_cls, context, query_field=None, query_limit=None, **kwargs):
38-
if not query_field and obj_cls.primary_keys:
39-
query_field = obj_cls.primary_keys[0]
40-
if query_field in obj_cls.fields_need_translation:
41-
query_field = obj_cls.fields_need_translation[query_field]
42-
return _get_filter_query(obj_cls, context, query_field=query_field,
43-
query_limit=query_limit, **kwargs).count()
40+
with db_api.CONTEXT_READER.using(context):
41+
if not query_field and obj_cls.primary_keys:
42+
query_field = obj_cls.primary_keys[0]
43+
if query_field in obj_cls.fields_need_translation:
44+
query_field = obj_cls.fields_need_translation[query_field]
45+
return _get_filter_query(obj_cls, context, query_field=query_field,
46+
query_limit=query_limit, **kwargs).count()
4447

4548

4649
def _kwargs_to_filters(**kwargs):

0 commit comments

Comments
 (0)