Skip to content

Commit 55a332b

Browse files
authored
Fix an issue with the type casting of default string function/procedure arguments in the debugger tool. #9036
1 parent 51bd866 commit 55a332b

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

web/pgadmin/tools/debugger/__init__.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,40 @@ def get_search_path(conn):
785785
return True, res
786786

787787

788+
def filter_params_by_default(params_list, default_value_str):
789+
"""
790+
Truncate params_list at the first index where the param matches the
791+
default value. If any subsequent param is present after default,
792+
error is raised.
793+
:param params_list:
794+
:param default_value_str:
795+
:return:
796+
"""
797+
default_values = []
798+
if default_value_str:
799+
# Split at comma, strip spaces, and add a space after index 0
800+
# as the arguments coming from frontend has space
801+
raw_defaults = str(default_value_str).split(',')
802+
default_values = [
803+
v.strip() if i == 0 else ' ' + v.strip()
804+
for i, v in enumerate(raw_defaults)
805+
]
806+
# Check for default value usage and subsequent params
807+
for idx, param in enumerate(params_list):
808+
if (idx < len(default_values) and str(param.get('value', '')) ==
809+
default_values[idx]):
810+
# If any subsequent param is present after default, error
811+
if any(str(p.get('value', '')) != default_values[i] for i, p in
812+
enumerate(params_list[idx + 1:], start=idx + 1)):
813+
return (None,
814+
gettext("Once a default value is passed, no "
815+
"subsequent arguments should be provided."))
816+
return params_list[:idx], None
817+
818+
# No params matched defaults, return all params
819+
return params_list, None
820+
821+
788822
@blueprint.route(
789823
'/initialize_target/<debug_type>/<int:trans_id>/<int:sid>/<int:did>/'
790824
'<int:scid>/<int:func_id>',
@@ -870,9 +904,14 @@ def initialize_target(debug_type, trans_id, sid, did,
870904
# provide the data from another session so below condition will
871905
# be be required
872906
if request.data:
873-
de_inst.function_data['args_value'] = \
874-
json.loads(request.data)
875-
907+
params_list = json.loads(request.data)
908+
params_list, error_msg = filter_params_by_default(
909+
params_list,
910+
de_inst.function_data['default_value']
911+
)
912+
if error_msg:
913+
return internal_server_error(errormsg=error_msg)
914+
de_inst.function_data['args_value'] = params_list
876915
# Update the debugger data session variable
877916
# Here frame_id is required when user debug the multilevel function.
878917
# When user select the frame from client we need to update the frame

0 commit comments

Comments
 (0)