From 8eb5e72ccdcc037d94209632f3e64742c809fd7e Mon Sep 17 00:00:00 2001 From: pyranota <92104930+pyranota@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:38:35 +0300 Subject: [PATCH] fix(python): Replace Inf with null (#5099) --- backend/windmill-worker/src/python_executor.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/windmill-worker/src/python_executor.rs b/backend/windmill-worker/src/python_executor.rs index c2696ed22f..68ba52c701 100644 --- a/backend/windmill-worker/src/python_executor.rs +++ b/backend/windmill-worker/src/python_executor.rs @@ -646,7 +646,7 @@ def to_b_64(v: bytes): b64 = base64.b64encode(v) return b64.decode('ascii') -replace_nan = re.compile(r'(?:\bNaN\b|\\*\\u0000)') +replace_invalid_fields = re.compile(r'(?:\bNaN\b|\\*\\u0000|Infinity|\-Infinity)') result_json = os.path.join(os.path.abspath(os.path.dirname(__file__)), "result.json") @@ -663,7 +663,7 @@ def res_to_json(res): for k, v in res.items(): if type(v).__name__ == 'bytes': res[k] = to_b_64(v) - return re.sub(replace_nan, ' null ', json.dumps(res, separators=(',', ':'), default=str).replace('\n', '')) + return re.sub(replace_invalid_fields, ' null ', json.dumps(res, separators=(',', ':'), default=str).replace('\n', '')) try: {preprocessor} @@ -2009,7 +2009,7 @@ def to_b_64(v: bytes): b64 = base64.b64encode(v) return b64.decode('ascii') -replace_nan = re.compile(r'(?:\bNaN\b|\\u0000)') +replace_invalid_fields = re.compile(r'(?:\bNaN\b|\\u0000|Infinity|\-Infinity)') sys.stdout.write('start\n') for line in sys.stdin: @@ -2037,7 +2037,7 @@ for line in sys.stdin: for k, v in res.items(): if type(v).__name__ == 'bytes': res[k] = to_b_64(v) - res_json = re.sub(replace_nan, ' null ', json.dumps(res, separators=(',', ':'), default=str).replace('\n', '')) + res_json = re.sub(replace_invalid_fields, ' null ', json.dumps(res, separators=(',', ':'), default=str).replace('\n', '')) sys.stdout.write("wm_res[success]:" + res_json + "\n") except BaseException as e: exc_type, exc_value, exc_traceback = sys.exc_info()