|
14 | 14 | import urllib.parse |
15 | 15 | from datetime import datetime |
16 | 16 | from json import JSONDecodeError |
17 | | -from typing import Callable, Dict, Iterable, List, Optional, Union |
| 17 | +from typing import Any, Callable, Dict, Iterable, List, Optional, Union |
18 | 18 |
|
19 | 19 | import requests |
20 | 20 | import requests.auth |
@@ -911,7 +911,27 @@ def _fix_query_string(query: Optional[dict] = None) -> Optional[dict]: |
911 | 911 | # See: https://github.com/databricks/databricks-sdk-py/issues/142 |
912 | 912 | if query is None: |
913 | 913 | return None |
914 | | - return {k: v if type(v) != bool else ('true' if v else 'false') for k, v in query.items()} |
| 914 | + with_fixed_bools = {k: v if type(v) != bool else ('true' if v else 'false') for k, v in query.items()} |
| 915 | + |
| 916 | + # Query parameters may be nested, e.g. |
| 917 | + # {'filter_by': {'user_ids': [123, 456]}} |
| 918 | + # The HTTP-compatible representation of this is |
| 919 | + # filter_by.user_ids=123&filter_by.user_ids=456 |
| 920 | + # To achieve this, we convert the above dictionary to |
| 921 | + # {'filter_by.user_ids': [123, 456]} |
| 922 | + # See the following for more information: |
| 923 | + # https://cloud.google.com/endpoints/docs/grpc-service-config/reference/rpc/google.api#google.api.HttpRule |
| 924 | + def flatten_dict(d: Dict[str, Any]) -> Dict[str, Any]: |
| 925 | + for k1, v1 in d.items(): |
| 926 | + if isinstance(v1, dict): |
| 927 | + v1 = dict(flatten_dict(v1)) |
| 928 | + for k2, v2 in v1.items(): |
| 929 | + yield f"{k1}.{k2}", v2 |
| 930 | + else: |
| 931 | + yield k1, v1 |
| 932 | + |
| 933 | + flattened = dict(flatten_dict(with_fixed_bools)) |
| 934 | + return flattened |
915 | 935 |
|
916 | 936 | def do(self, |
917 | 937 | method: str, |
|
0 commit comments