Open-EO / openeo-python-client

Python client API for OpenEO
https://open-eo.github.io/openeo-python-client/
Apache License 2.0
156 stars 42 forks source link

Parameter encoding bug in run_udf with context #431

Closed soxofaan closed 1 year ago

soxofaan commented 1 year ago

(bug reported by @mbuchhorn ). Minimal reproduction example

import openeo
from openeo.api.process import Parameter
from openeo.rest.udp import build_process_dict

connection = openeo.connect(...)

param = Parameter("foo_param")
s2_cube = connection.load_collection("SENTINEL2_L2A")

udf = openeo.UDF("print('hello world')", runtime="Python", context={"foo": foo_param})
cube = s2_cube.apply(process=udf)

print(json.dumps(build_process_dict(cube, parameters=[foo_param]), indent=2))

Fails with

TypeError: Object of type Parameter is not JSON serializable
soxofaan commented 1 year ago

something like this works:

cube = s2_cube.apply(lambda x: x+ foo_param)

print(json.dumps(build_process_dict(cube, parameters=[foo_param]), indent=2))

so it has something to do with putting the param in the context of the UDF