Skip to content

Fix failed UDF query#233

Open
chimosky wants to merge 7 commits into
roostorg:mainfrom
chimosky:failed-udf-query
Open

Fix failed UDF query#233
chimosky wants to merge 7 commits into
roostorg:mainfrom
chimosky:failed-udf-query

Conversation

@chimosky
Copy link
Copy Markdown
Contributor

@chimosky chimosky commented Apr 24, 2026

Description

Before now, using a UDF in a query threw this error;

File \"/osprey/osprey_worker/src/osprey/engine/query_language/ast_druid_translator.py\", line 102, in transform_Call
     udf, _ = self._udf_node_mapping[id(node)]
              ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 139836295173120"}

This happened because all the validators weren't being run during a query, for some reason the REGISTRY didn't load all, just the additional ones that are needed for a query.

DidAddLabel was also affected by this, this also fixes that.

Fixes #158

I've added changes to uv.lock because the precommit hook fails without it for some reason;

mypy.....................................................................Failed
- hook id: mypy
- files were modified by this hook

Checklist

  • Tests pass locally
  • uv run ruff check . passes (no unused imports or other lint errors)
  • uv tool run fawltydeps --check-unused --pyenv .venv passes (no unused dependencies)
  • Updated CHANGELOG.md with my changes, if applicable

Before now, using a UDF in a query threw this error;

File \"/osprey/osprey_worker/src/osprey/engine/query_language/ast_druid_translator.py\", line 102, in transform_Call
     udf, _ = self._udf_node_mapping[id(node)]
              ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 139836295173120"}

This happened because all the validators weren't being run during a
query, for some reason the REGISTRY didn't load all, just the additional
ones that are needed for a query.

DidAddLabel was also affected by this, this also fixes that.

I've also modified RegexMatch to use the right arguments as used in the
docs, item and regex created confusion as the docs stated target and
pattern, and using that in the query threw an error.

Signed-off-by: Chihurumnaya Ibiam <ibiamchihurumnaya@gmail.com>
Signed-off-by: Chihurumnaya Ibiam <ibiamchihurumnaya@gmail.com>
@haileyok
Copy link
Copy Markdown
Member

oh yea, i encountered this before as well iirc. thanks for looking and fixing!

can you pull out the uv.lock changes before we merge please?

Signed-off-by: Chihurumnaya Ibiam <ibiamchihurumnaya@gmail.com>
@chimosky
Copy link
Copy Markdown
Contributor Author

can you pull out the uv.lock changes before we merge please?

Done, I know I wasn't supposed to include it but I'd run into some issues at the time with the pre-commit hook failing and I had to include it in the commit, forgot to revert it once I'd gotten past that.

Signed-off-by: Chihurumnaya Ibiam <ibiamchihurumnaya@gmail.com>
@haileyok
Copy link
Copy Markdown
Member

yea no worries. tbh we might be able to come up with some sort of hook that checks to make sure that doesn't happen, but im not really sure what the best wya to go about it is if im being honest


def test_regex_match_accepts_valid_call(run_validation: RunValidationFunction) -> None:
run_validation("RegexMatch(item=A, regex='^foo$')")
run_validation("RegexMatch(target=A, pattern='^foo$')")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i believe that test snapshots need to get updated for this (and others)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment on lines +75 to +85
def _consolidate_registry(self, validator_registry: ValidatorRegistry) -> ValidatorRegistry:
validators = {
validator
for validator in ValidatorRegistry.get_instance().get_validators()
if not validator.exclude_from_query_validation
}
registry_validators = set()
for validator in validator_registry.get_validators():
registry_validators.add(validator)

return ValidatorRegistry.from_validator_classes(validators.union(registry_validators))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does doing this break any existing tests or functionality? it seems like this may break cases where we try to explicitly use only one or two validators (i think mostly for testing).

Copy link
Copy Markdown
Contributor Author

@chimosky chimosky Apr 29, 2026

Choose a reason for hiding this comment

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

Yes, it does break existing functionality and I've fixed that.

How do I update test snapshots as it seems that's the only reason the test is failing right now, the test says to use --write-outputs option and I can see the argument should be loaded as part of the engine.conftest plugin but it seems that happens later than it should so it's basically nonexistent.

I can't run pytest --snapshot-update in the directory as I don't have osprey and gevent installed locally, as they're supposed to be installed in the dev environment.

@chimosky
Copy link
Copy Markdown
Contributor Author

yea no worries. tbh we might be able to come up with some sort of hook that checks to make sure that doesn't happen, but im not really sure what the best wya to go about it is if im being honest

Might give it a look and see if I figure something out.

cassidyjames and others added 2 commits May 15, 2026 11:39
I've moved loading all the registeries needed for a query to when a query is made,
this is where it should be and it shouldn't affect existing behaviour.

Signed-off-by: Chihurumnaya Ibiam <ibiamchihurumnaya@gmail.com>
@chimosky chimosky force-pushed the failed-udf-query branch from 95cec18 to 6d21e09 Compare May 18, 2026 14:57
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.

Failed UDF -> Druid query filter translation

3 participants