Skip to content

Commit beaed42

Browse files
committed
Replace context decorators with context managers
The context decorator needs to have the "context" parameter in the first position or the first argument must be "self" or "cls", followed by the "context" object. Closes-Bug: #2017784 Change-Id: Ib80f7c72e78854226b227e354792320c78fed5d0 (cherry picked from commit 4e27e27)
1 parent 92cfdb4 commit beaed42

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

neutron/objects/db/api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def _get_filter_query(obj_cls, context, query_field=None, query_limit=None,
3030
return query
3131

3232

33-
@db_api.CONTEXT_READER
3433
def get_object(obj_cls, context, **kwargs):
35-
return _get_filter_query(obj_cls, context, **kwargs).first()
34+
with db_api.CONTEXT_READER.using(context):
35+
return _get_filter_query(obj_cls, context, **kwargs).first()
3636

3737

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

4747

4848
def _kwargs_to_filters(**kwargs):

0 commit comments

Comments
 (0)