Open JeroenVerstraelen opened 10 months ago
I'd like to point out that this is not only a client issue, but a less obvious part of openeo process graphs with run_udf.
There are multiple ways to get "configuration" or context
into a UDF:
Directly in run_udf
:
{
"process_id": "run_udf"
"arguments": {
...
"context": {"color": "red"}
or through the parent process, e.g. apply
{
"process_id": "apply",
"arguments": {
...
"process": {
...
"runudf1": {
"process_id": "run_udf",
"arguments": {
"context": {"from_parameter": "context"}
...
.....
"context": {"color": "red"}
note that the context
from apply
has to be passed through explicitly by run_udf
with {"from_parameter": "context"}
.
If you forget that passing through you get in the situation mentioned above
the following code does not pass the context to his UDF ...
The first solution (direct context
in run_udf
) is obviously the easiest, e.g. as proposed above too
solution was to pass the context in the from_file method instead
However, the solution with passing through the context from "upstream" is still important to cover, e.g. in UDPs or services where the context or parts of the context come from (UDP) parameters.
regardless, we can at least throw warnings client side when it looks like the user might have forgotten something to get the context inside the UDF properly
an alternative solution is to use {"from_parameter": "context"}
by default in run_udf
if there is a context set by the parent process.
This is also something we could check for (e.g. in /validation
or runtime warning) back-end side
Note that most of our examples in python client do not show how to use the context. Just adding that there would probably help a lot, as users can then just copy-paste a working example?
an alternative solution is to use {"from_parameter": "context"} by default in run_udf if there is a context set by the parent process.
=>
A user let us know that the following code does not pass the context to his UDF:
The solution was to pass the context in the from_file method instead:
We should either: