Skip to content

Conversation

@cmttt
Copy link
Collaborator

@cmttt cmttt commented Jan 8, 2026

UDFs that return a custom type will break the UI's extracted features -> values mapping, so we need a validator that checks that we aren't implementing any rules that return a custom type.

@cmttt cmttt force-pushed the ls/extracted-feature-validator branch from ccc5489 to e236c8a Compare January 8, 2026 22:16
from osprey.engine.language_types.entities import EntityT
from osprey.engine.udf.type_helpers import to_display_str

from ..base_validator import SourceValidator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the full osprey.engine.* path for consistency.

To use a custom type without extraction, prefix the variable name with `_` to make
it a local variable:
_VC1 = CustomUdf(entity=TestUser) # OK - not extracted
VC1 = CustomUdf(entity=TestUser) # ERROR - would be extracted
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coming in without too much context, and I do remember this is a thing we do, but its kinda a hack in the first place, assigning some semantic meaning to the name of a variable is pretty unexpected.

Definitely think this validator is a positive, but we should think about what we want a better API to look like in the future (in_the_backlog.gif)

non_none_args = [a for a in args if a is not type(None)] # noqa: E721
# Optional is a Union with exactly one non-None type
if len(non_none_args) == 1:
return _is_extractable_type(non_none_args[0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool recursion

# Check Optional[T] (which is Union[T, None] at runtime)
if typing_inspect.is_union_type(t):
args = typing_inspect.get_args(t)
non_none_args = [a for a in args if a is not type(None)] # noqa: E721
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this also allows Union[T], but I guess we dont really care

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.

4 participants