Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dagster-yaml] yaml pydantic parsing utils #21824

Merged
merged 1 commit into from
May 21, 2024
Merged

[dagster-yaml] yaml pydantic parsing utils #21824

merged 1 commit into from
May 21, 2024

Conversation

sryza
Copy link
Contributor

@sryza sryza commented May 13, 2024

Summary & Motivation

Tools for parsing YAML files into pydantic models, preserving information about source positions, including those source positions in validation errors.

Adapted from @petehunt's versions of these in the internal repo.

How I Tested These Changes

@sryza sryza changed the title [dagster-yaml] scaffolding and utils [dagster-yaml] scaffolding and yaml utils May 13, 2024
@sryza sryza force-pushed the definitions-merge branch 4 times, most recently from 914722a to a83d2dc Compare May 20, 2024 17:17
@sryza sryza force-pushed the dagster-yaml-utils branch 2 times, most recently from af61cdb to eec9bf4 Compare May 20, 2024 18:37
@sryza sryza marked this pull request as ready for review May 20, 2024 18:38
@sryza sryza changed the title [dagster-yaml] scaffolding and yaml utils [dagster-yaml] yaml pydantic parsing utils May 20, 2024
@sryza sryza requested a review from benpankow May 20, 2024 18:39
Copy link
Member

@benpankow benpankow left a comment

Choose a reason for hiding this comment

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

This is slick - few pedantic comments inline but impl looks good to me

obj._source_position_and_key_path is not None # noqa: SLF001
and obj._source_position_and_key_path != source_position_and_key_path # noqa: SLF001
):
raise RuntimeError(
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for this? Just to make sure we don't accidentally do duplicate work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah just something has probably gone wrong if we end up here. Changed it to a check.invariant.

python_modules/dagster/dagster/_utils/pydantic_yaml.py Outdated Show resolved Hide resolved
source_position = SourcePosition(
filename=filename,
start=LineCol(
line=node.start_mark.line + 1,
Copy link
Member

Choose a reason for hiding this comment

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

assume this is zero-index-to-one-index? might be worth noting inline or in LineCol docstring that that is the case

class SafeLineLoader(yaml.SafeLoader):
@classmethod
def remove_implicit_resolver(cls, tag_to_remove: Any) -> None:
if "yaml_implicit_resolvers" not in cls.__dict__:
Copy link
Member

Choose a reason for hiding this comment

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

what's the deal with this? assume it's some yaml pkg weirdness, but is there some weird logic where yaml_implicit_resolvers is available via attribute access but is not actually an attribute on the class?

this fn feels all like a little bit of black magic since it's dealing w/ SafeLoader internals, could be good to add some context

@sryza sryza force-pushed the dagster-yaml-utils branch 4 times, most recently from cb39a4e to e2fb58c Compare May 21, 2024 16:25
branch-name: dagster-yaml-utils
@graphite-app graphite-app bot added the area: docs Related to documentation in general label May 21, 2024
@sryza sryza changed the base branch from definitions-merge to master May 21, 2024 19:29
@sryza sryza merged commit 4f5eca7 into master May 21, 2024
1 of 3 checks passed
@sryza sryza deleted the dagster-yaml-utils branch May 21, 2024 19:29
nikomancy pushed a commit that referenced this pull request May 22, 2024
## Summary & Motivation

Tools for parsing YAML files into pydantic models, preserving
information about source positions, including those source positions in
validation errors.

Adapted from @petehunt's versions of these in the internal repo.

## How I Tested These Changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Related to documentation in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants