-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Clone from non-parameters #1630
Clone from non-parameters #1630
Conversation
not sure about this. it seems too magic and i think it could lead to unexpected behavior later. what's the issue you're trying to solve here? your example isn't very useful because |
Yeah maybe, the failing tests (which I haven't digested yet) might suggest this as well. Here's a slightly more fleshed out use case to describe where I'm coming from: In practice the Upload and UploadFromManifest tasks (which I actually do use), have several more parameters:
we use the generic UploadFromManifest in several different pipelines to transfer data between services. In most concrete cases all of the parameters in in RequestMixin are either known at task-definition time, or derived from a more context-specific parameter. So they might be specifiable as something like:
This PR makes the above code functional, and I rather like its flat+declarative structure. Without it you'd need to write:
ie you lose the intended benefits of clone (not having to re-enumerate every parameter when describing dependencies). Furthermore the first example throws an exception like Another small consideration: the following code works currently (maybe you'd consider it an antipattern, I'm not sure):
In other words, overriding parameters with class-level attributes or properties currently works, but propagating these overrides through clone does not. That feels a little asymmetrical to me. However, maybe you disagree, or there's another mechanism for addressing this use case that I'm missing? |
I'm quite positive to this change and I find this to make sense. We want the clone-behavior for Parameter-attributes to feel as similar as possible for other attributes. Let me know what insights you can get from the failed test case. |
@Tarrasch @erikbern ok the problematic test case boils down to this: class X(luigi.Task):
n = luigi.IntParameter(default=42)
@inherits(X)
class Z(luigi.Task):
n = None
def requires(self):
return self.clone_parent()
assert Z().requires().n == 42 or more simply class X(luigi.Task):
n = luigi.IntParameter(default=42)
class Z(luigi.Task):
n = None
assert Z().clone(cls=X).n == 42 It was added in this commit by @erikbern The intention of this PR is to change that behavior, so that |
So the real issue you are trying to solve here is you want a subclass to be able to override base class parameter and fix them to certain value? I haven't thought of this use case |
Well this is already possible -- a subclass can override base class parameters with constants (class attributes or properties). I'm proposing the override behavior for |
IMO the utility of this comes into play when you extract out common generic tasks. Because they are general-purpose, they often need several parameters to be fully specified. But often times those settings should not be considered "parametrize-able" in the downstream, special-purpose task. For example the |
@ChrisBeaumont any updates on this? |
Thanks @ChrisBeaumont. After reading this once and twice. It's clear to me that this new behavior is better and makes more sense. Usually the luigi dictators are pretty hesitant to changes to luigi core hence the prolonged discussion. I hope it wasn't discouraging and sorry for the very long delay in merging! |
Currently
Task.clone
only propagates values from source to target when both attributes are Parameters. This PR propagates data from source to target parameter regardless of whether the source attribute is a parameter or something else (property, class or instance-level attribute, etc).The use case for this has come up in cases where we interface between generic and specific tasks. A simplified example, consider some generic classes to POST several files referenced in a manifest to an external url:
as well as a more specific subtask where url is derived from a more fundamental parameter:
This fails at the clone step because, although url is defined for
MonthlyReport
, it's not a parameter and thus not propagated toUpload