From 8ee4889a5e5883745c676a9f64502efad94b2469 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 25 Jan 2022 16:56:52 +0100 Subject: [PATCH] feat(api): sessions search fixed isNot index feat(api): sessions search by metadata use source instead of key --- api/chalicelib/core/sessions.py | 8 ++++---- api/schemas.py | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index f5617789d..113c2c754 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -384,12 +384,12 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr meta_keys = metadata.get(project_id=project_id) meta_keys = {m["key"]: m["index"] for m in meta_keys} # op = __get_sql_operator(f.operator) - if f.key in meta_keys.keys(): + if f.source in meta_keys.keys(): extra_constraints.append( - _multiple_conditions(f"s.{metadata.index_to_colname(meta_keys[f.key])} {op} %({f_k})s", + _multiple_conditions(f"s.{metadata.index_to_colname(meta_keys[f.source])} {op} %({f_k})s", f.value, is_not=is_not, value_key=f_k)) ss_constraints.append( - _multiple_conditions(f"ms.{metadata.index_to_colname(meta_keys[f.key])} {op} %({f_k})s", + _multiple_conditions(f"ms.{metadata.index_to_colname(meta_keys[f.source])} {op} %({f_k})s", f.value, is_not=is_not, value_key=f_k)) elif filter_type in [schemas.FilterType.user_id, schemas.FilterType.user_id_ios]: # op = __get_sql_operator(f.operator) @@ -682,7 +682,7 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr AND start_ts >= %(startDate)s AND start_ts <= %(endDate)s AND duration IS NOT NULL - ) {"" if or_events else ("AS event_{event_index}" + ("ON(TRUE)" if event_index > 0 else ""))}\ + ) {"" if or_events else (f"AS event_{event_index}" + ("ON(TRUE)" if event_index > 0 else ""))}\ """) else: events_query_from.append(f"""\ diff --git a/api/schemas.py b/api/schemas.py index 0c3493121..a09178df9 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -502,16 +502,18 @@ class _SessionSearchEventSchema(_SessionSearchEventRaw): class _SessionSearchFilterSchema(__MixedSearchFilter): is_event: bool = Field(False, const=False) custom: Optional[List[str]] = Field(None) - key: Optional[str] = Field(None) value: Union[Optional[Union[IssueType, PlatformType, int, str]], Optional[List[Union[IssueType, PlatformType, int, str]]]] = Field(...) type: FilterType = Field(...) operator: Union[SearchEventOperator, MathOperator] = Field(...) - source: Optional[ErrorSource] = Field(default=ErrorSource.js_exception) + source: Optional[Union[ErrorSource, str]] = Field(default=ErrorSource.js_exception) @root_validator def filter_validator(cls, values): - if values.get("type") == FilterType.issue: + if values.get("type") == FilterType.metadata: + assert values.get("source") is not None and len(values["source"]) > 0, \ + "must specify a valid 'source' for metadata filter" + elif values.get("type") == FilterType.issue: for v in values.get("value"): assert isinstance(v, IssueType), f"value should be of type IssueType for {values.get('type')} filter" elif values.get("type") == FilterType.platform: