Skip to content

Commit

Permalink
Replace context decorators with context managers
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ralonsoh committed Apr 23, 2023
1 parent 92cfdb4 commit beaed42
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions neutron/objects/db/api.py
Expand Up @@ -30,19 +30,19 @@ def _get_filter_query(obj_cls, context, query_field=None, query_limit=None,
return query


@db_api.CONTEXT_READER
def get_object(obj_cls, context, **kwargs):
return _get_filter_query(obj_cls, context, **kwargs).first()
with db_api.CONTEXT_READER.using(context):
return _get_filter_query(obj_cls, context, **kwargs).first()


@db_api.CONTEXT_READER
def count(obj_cls, context, query_field=None, query_limit=None, **kwargs):
if not query_field and obj_cls.primary_keys:
query_field = obj_cls.primary_keys[0]
if query_field in obj_cls.fields_need_translation:
query_field = obj_cls.fields_need_translation[query_field]
return _get_filter_query(obj_cls, context, query_field=query_field,
query_limit=query_limit, **kwargs).count()
with db_api.CONTEXT_READER.using(context):
if not query_field and obj_cls.primary_keys:
query_field = obj_cls.primary_keys[0]
if query_field in obj_cls.fields_need_translation:
query_field = obj_cls.fields_need_translation[query_field]
return _get_filter_query(obj_cls, context, query_field=query_field,
query_limit=query_limit, **kwargs).count()


def _kwargs_to_filters(**kwargs):
Expand Down

0 comments on commit beaed42

Please sign in to comment.