-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[RFC][dagster-powerbi] Implement copy_with_context in DagsterPowerBITranslator #26617
[RFC][dagster-powerbi] Implement copy_with_context in DagsterPowerBITranslator #26617
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@@ -437,7 +437,7 @@ def fetch_state(self) -> PowerBIWorkspaceData: | |||
) | |||
|
|||
def defs_from_state(self, state: PowerBIWorkspaceData) -> Definitions: | |||
translator = self.translator_cls(context=state) | |||
translator = self.translator_cls().copy_with_context(context=state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
State-backed defs and spec loader to accept a translator instance in a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board with all the stuff about passing an instance of the translator etc.
However, I think it's probably too sketchy to try to infer the init arguments and reconstruct the class etc.
It'd work for a lot of cases but I think it's not intuitive for the user that their custom init function would get called twice, and I don't have high confidence that there isn't some sneaky way of breaking this with fancy parameter specs (like **kwargs etc.)
We usually avoid mutable objects (for good reason), but I think this is a prime example of a place where that'd be a better solution.
We could just have:
class DagsterPowerBITranslator:
_context: Optional[PowerBiWorkspaceData]
def set_context(self, context: PowerBiWorkspaceData) -> None:
self._context = context
@property
def context(self) -> PowerBIWorkspaceData:
return check.not_none(self._context, "helpful message explaining you probbably called a method outside of framework code")
This lets us avoid all the fancy inspect
stuff and is much easier to wrap your head around (imo)
We usually avoid mutable objects (for good reason), but I think this is a prime example of a place where that'd be a better solution. @OwenKephart I agree with you 100%. I just updated the description of this PR to add proposals that were not retained. Your proposal was previously suggested, but not retained because it would make the object mutable. That said, I agree that inferring the init arguments from the instance is error-prone. @schrockn Considering the implementation it requires to make the object immutable, do you think it would be a reasonable trade-off to use a setter and make this object mutable? I think there'd be a lot less risk of error. |
Closing this RFC - we found an alternative, see here. |
Summary & Motivation
This PR is motivated by this discussion
Context:
Translators for BI integrations required the contextual data from the workspace to create the asset specs. To pass this data to the translator, we ask users to pass the type of the translator to the spec loader, and we initialize the translator with its context in the state-back defs.
This approach works well, but is not flexible for users that want to customize their translators - users often customize the
__init__
method, but passing this approach prevent them to initialize the translator with the correct arguments.We want to update BI integrations so that users can pass an instance of the translator to spec loaders, which is more flexible, instead of the type.
Challenges:
__init__
method and add new parameters to its signature, which are unknown to usSolution:
Use the
copy_with_context
method to rebuild a translator with its context.To make this possible we need to:
__init__
kwargs from the attributes and the__init__
signature, using_get_init_kwargs_from_instance
__init__
method of a custom translatorSo, to make this possible, we require a few things from users:
__init__
method must include thecontext
parameter__init__
param, eg. the attribute formy_param
can bemy_param
or_my_param
Proposals that were not retained:
How I Tested These Changes
New tests with BK
Changelog