Skip to content

Name the UDF signatures found when no UDF matches - #980

Closed
sandeshbagmare wants to merge 1 commit into
Open-EO:masterfrom
sandeshbagmare:fix/udf-no-match-error-message
Closed

sandeshbagmare wants to merge 1 commit into
Open-EO:masterfrom
sandeshbagmare:fix/udf-no-match-error-message

Conversation

@sandeshbagmare

Copy link
Copy Markdown

Fixes #545

When the arguments of the entrypoint do not match a supported UDF signature, run_udf_code only said No UDF found.. The most common cause is a correct function name with the type annotations left out (def apply_datacube(cube, context)), which reads as a broken UDF library rather than a broken signature.

Proposed Changes

  • Collect the name and signature of every function the UDF code defines and name them in the exception, so the user sees what was found next to what was expected.
  • Point at the reference for UDF function names and signatures, which says the annotations are part of the signature.
  • Skip the types the execution context pre-loads (UdfData, XarrayDataCube, ...). They are callable, but never entrypoints, and would otherwise dominate the message.

Before:

openeo.udf.OpenEoUdfException: No UDF found.

After, for a UDF that defines def apply_datacube(cube, context):

No UDF found: none of the functions in the UDF code has a supported UDF signature.
Found: `apply_datacube(cube, context)`. The function name and its type annotations
decide how the UDF is called, so they cannot be left out
(see https://open-eo.github.io/openeo-python-client/udf.html#udf-function-names-and-signatures).

Tests

Two cases added to tests/udf/test_run_code.py: one for a function that is named correctly but unannotated, one for code that defines no function at all.

pytest tests/udf passes (124 passed, 6 skipped). The wider suite has pre-existing failures in tests/utils/test_http.py and the S3 extra that are unrelated to this change and also fail on master here.

A UDF whose entrypoint is named correctly but leaves out the type
annotations, as in 'def apply_datacube(cube, context)', only produced
'No UDF found.', which does not say which part of the signature was wrong.

Collect the name and signature of every function the UDF code defines and
include them in the exception, together with a pointer to the reference for
UDF function names and signatures. Types the execution context pre-loads,
like UdfData, are callable but are never entrypoints, so they are skipped.

Fixes Open-EO#545
@sandeshbagmare

Copy link
Copy Markdown
Author

Closing this as duplicate work: #848 already rewrites run_udf_code for #545 and is still open, so it should not be competing with a second pull request for the same issue. #981, the documentation side of the same area, is unrelated and stays open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specify Exception for "No UDF found" when the arguments are incorrect

1 participant