From 6b5ceed6525d4251517627351a15a4fe604629fc Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 9 May 2023 09:36:07 +0200 Subject: [PATCH] feat(backend): in python, if a value is bytes, it is encoded to base64 automaticaly --- backend/windmill-worker/src/python_executor.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/windmill-worker/src/python_executor.rs b/backend/windmill-worker/src/python_executor.rs index 83a39ce779..43cd566997 100644 --- a/backend/windmill-worker/src/python_executor.rs +++ b/backend/windmill-worker/src/python_executor.rs @@ -325,6 +325,11 @@ for k, v in list(args.items()): if v == '': del args[k] +def to_b_64(v: bytes): + import base64 + b64 = base64.b64encode(v) + return b64.decode('ascii') + try: res = inner_script.main(**args) typ = type(res) @@ -333,6 +338,12 @@ try: res = res.values.tolist() elif typ.__module__ == 'polars.dataframe.frame': res = res.rows() + elif typ.__name__ == 'bytes': + res = to_b_64(res) + elif typ.__name__ == 'dict': + for k, v in res.items(): + if type(v).__name__ == 'bytes': + res[k] = to_b_64(v) res_json = json.dumps(res, separators=(',', ':'), default=str).replace('\n', '') with open("result.json", 'w') as f: f.write(res_json)