Skip to content

Commit

Permalink
hotfix: added backward compatability for advanced params (#29)
Browse files Browse the repository at this point in the history
* Remove operator and value in payload if they are None in AdvancedParams

Sample:

```python
{
    'app': 'vanilla-search',
    'query': {
        'name': 'query',
        'text': 'himawari',
        'isFirstpage': False,
        'strictRefine': False,
        'removeDuplicates': False,
        'action': 'search',
        'page': 1,
        'pageSize': 10,
        'advanced': {
            'collection': '/user_needs_database/snwg-assessments-2020/',
            # 'value': None, 'operator': None,
        }
    }
}
```

* Bugfix payload generation for AdvancedParams

Now col_name and values are checked to see if empty.

* added support for advanced params according to documentation

* fixed support for single or multiple advanced params

---------

Co-authored-by: NISH1001 <nishanpantha@gmail.com>
  • Loading branch information
anisbhsl and NISH1001 authored Feb 27, 2024
1 parent 4fabf47 commit 58f4fc8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pynequa/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Union
from abc import abstractmethod, ABC
from dataclasses import dataclass, field
from loguru import logger
Expand Down Expand Up @@ -168,7 +168,7 @@ class QueryParams(AbstractParams):
aggregations: Optional[List[str]] = field(default_factory=lambda: [])
order_by: Optional[str] = None
group_by: Optional[str] = None
advanced: Optional[List[AdvancedParams]] = field(
advanced: Optional[Union[AdvancedParams, List[AdvancedParams]]] = field(
default_factory=lambda: [])
debug: bool = False

Expand Down Expand Up @@ -256,9 +256,14 @@ def _prepare_query_args(self, query_name: str) -> Dict:
if self.group_by is not None:
params["groupBy"] = self.group_by

if len(self.advanced) > 0:
advanced = (
[self.advanced]
if isinstance(self.advanced, AdvancedParams)
else self.advanced
)
if len(advanced) > 0:
advanced_param_payload = {}
for advanced_param in self.advanced:
for advanced_param in advanced:
column_name = advanced_param.col_name
payload_value = advanced_param.generate_payload()[column_name]
if column_name in advanced_param_payload:
Expand Down

0 comments on commit 58f4fc8

Please sign in to comment.