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 4e27e27ae2
)
This commit is contained in:
parent
78a24a3a75
commit
0d3998c742
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue