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

[components] Use AssetAttributesModel instead of DbtTranslatorParams #26768

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

OwenKephart
Copy link
Contributor

Summary & Motivation

This converts to using the AssetAttributesModel inside the translator. This is nice because it reduces duplicated code (e.g. the AssetKey.from_user_string() conversion), and in general having fewer distinct types flying around is good. (note: the group_name key was erroneously called just group before, this is something that we now no longer need to worry about)

Unfortunately, the translator code is still a mess on account of not having a unified get_asset_spec() method, meaning we have to implement a bunch of individual fns. However, once that's implemented, the translator can become as simple as:

class XComponentTranslator(XTranslator):

    def __init__(self, params: AssetAttributes, resolver): ...

    def get_asset_spec(self, x: ...) -> AssetSpec:
        base_spec = super().get_asset_spec(x)
        rendered_props = params.get_rendered_properties(resolver.with_context(x=x))
        return base_spec.replace_attributes(**rendered_props)

How I Tested These Changes

Changelog

NOCHANGELOG

Copy link
Contributor Author

OwenKephart commented Dec 31, 2024

Comment on lines +83 to +87
def _render_property(
self, key: str, raw_value: Any, value_resolver: "TemplatedValueResolver"
) -> Any:
return value_resolver.render_obj(raw_value)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is easier to override on a per-key basis

@OwenKephart OwenKephart force-pushed the 12-31-_components_use_assetattributesmodel_instead_of_dbttranslatorparams branch from 174254c to 8524932 Compare December 31, 2024 20:15
Comment on lines +45 to +51
def _render_property(self, key, raw_value, value_resolver):
rendered = super()._render_property(key, raw_value, value_resolver)
if key == "key":
# coerce the string asset key into an AssetKey object
return AssetKey.from_user_string(rendered) if rendered else None
return rendered

Copy link
Member

Choose a reason for hiding this comment

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

this seems super gross and instead there should more structured and well-typed way of doing this (like a callback attached to RenderingMetadata)

Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

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

Not a fan of render_property specifically

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.

2 participants