sdk-codegen
sdk-codegen copied to clipboard
Python: check runtime type of path param before urlencoding
currently we check the static type to decide whether to encode but at runtime the value could be an int and then we blow up with
~/Documents/sdk-codegen/python/looker_sdk/sdk/api31/methods.py in dashboard_layout_dashboard_layout_components(self, dashboard_layout_id, fields, transport_options)
2612 ) -> Sequence[models.DashboardLayoutComponent]:
2613 """Get All DashboardLayoutComponents"""
-> 2614 dashboard_layout_id = self.encode_path_param(dashboard_layout_id)
2615 response = self.get(
2616 f"/dashboard_layouts/{dashboard_layout_id}/dashboard_layout_components",
~/Documents/sdk-codegen/python/looker_sdk/rtl/api_methods.py in encode_path_param(value)
117 @staticmethod
118 def encode_path_param(value: str) -> str:
--> 119 if value == urllib.parse.unquote(value):
120 value = urllib.parse.quote(value, safe="")
121 return value
~/.pyenv/versions/3.8.2/lib/python3.8/urllib/parse.py in unquote(string, encoding, errors)
632 unquote('abc%20def') -> 'abc def'.
633 """
--> 634 if '%' not in string:
635 string.split
636 return string
TypeError: argument of type 'int' is not iterable
@jkaster is this issue still valid?
@joeldodge79 @josephaxisa do you know the status of this?
I'd have to look at the code: probably still a theoretical issue (if the API advertises a string type but sends back an int). but I don't think we've had any customer reports on this so might just not be an issue
Hi,
I wanted to report that I'm running into this exact issue on python looker-sdk 22.4.0.
Is there a way to resolve this?
{
"errorMessage": "argument of type 'int' is not iterable",
"errorType": "TypeError",
"requestId": "cfe47092-ec2e-48ed-b519-f93993be2626",
"stackTrace": [
...
" File \"/var/task/model_explainability/apps/datapull.py\", line 92, in get_data\n look = sdk.look(584)\n",
" File \"/var/lang/lib/python3.9/site-packages/looker_sdk/sdk/api40/methods.py\", line 6407, in look\n look_id = self.encode_path_param(look_id)\n",
" File \"/var/lang/lib/python3.9/site-packages/looker_sdk/rtl/api_methods.py\", line 122, in encode_path_param\n if value == urllib.parse.unquote(value):\n",
" File \"/var/lang/lib/python3.9/urllib/parse.py\", line 656, in unquote\n if '%' not in string:\n"
]
}
@joeldodge79 I just got this error today. This error does not occur when I use 3.1 but on 4.0 I get this error straight away.
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/looker_sdk/sdk/api40/methods.py:7105, in Looker40SDK.run_look(self, look_id, result_format, limit, apply_formatting, apply_vis, cache, image_width, image_height, generate_drill_links, force_production, cache_only, path_prefix, rebuild_pdts, server_table_calcs, transport_options)
7072 def run_look(
7073 self,
7074 # Id of look
(...)
7102 transport_options: Optional[transport.TransportOptions] = None,
7103 ) -> Union[str, bytes]:
7104 """Run Look"""
-> 7105 look_id = self.encode_path_param(look_id)
7106 result_format = self.encode_path_param(result_format)
7107 response = cast(
7108 Union[str, bytes],
7109 self.get(
(...)
7114 )
7115 )
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/looker_sdk/rtl/api_methods.py:128, in APIMethods.encode_path_param(value)
126 @staticmethod
127 def encode_path_param(value: str) -> str:
--> 128 if value == urllib.parse.unquote(value):
129 value = urllib.parse.quote(value, safe="")
130 return value
File /usr/lib/python3.10/urllib/parse.py:668, in unquote(string, encoding, errors)
666 if isinstance(string, bytes):
667 return unquote_to_bytes(string).decode(encoding, errors)
--> 668 if '%' not in string:
669 string.split
670 return string
TypeError: argument of type 'int' is not iterable