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

Make luigi.task.externalize return shallow copies #1952

Merged

Conversation

Tarrasch
Copy link
Contributor

@Tarrasch Tarrasch commented Dec 5, 2016

Description

Currently, running externalize on an existing class or object will have
serious side effects. Like subsequently created objects from the
original passed in class will also be externalized. This patch changes
the behavior to return a changed copy and not having as much side-effects.

Secondly, this patch officially declares this function to work on both
classes and objects.
I see two reasons we should allow for this (possibly) overly dynamic
behavior in both accepting classes and objects. First, novice users
don't pay attention to the difference, second, it still possible and it
will seem to work to pass in the class instead of the object. I was at
least tempted to without being sure if it was "correct". Instead let's
try to be soft on the users for this case.

Have you tested this? If so, how?

I added many test cases and I've tested this in a little bit of production code.

@mention-bot
Copy link

@Tarrasch, thanks for your PR! By analyzing the history of the files in this pull request, we identified @steenzout, @gpoulin and @erikbern to be potential reviewers.

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Dec 5, 2016

Here's the rendered docs:

selection_073

edit: This turned out wrong. Let me make the docs look good as well!

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Dec 5, 2016

Actually, I think this needs to return a copy of the original class and or object.

@Tarrasch Tarrasch force-pushed the specify_externalize_behaviour_clearly branch 2 times, most recently from 3213d40 to 2aefc92 Compare December 5, 2016 09:45
@Tarrasch
Copy link
Contributor Author

Tarrasch commented Dec 5, 2016

Note to self: Mutating stuff is bad >_<

Here's a new version of the docs.

selection_074

@Tarrasch Tarrasch changed the title Document that luigi.task.externalize is flexible Make luigi.task.externalize return shallow copies Dec 5, 2016
@Tarrasch
Copy link
Contributor Author

Tarrasch commented Dec 5, 2016

I will also try the @luigi.util.requires(externalize(MyTask)) to see if it actually works for me in production. If it does It's a win for modularity. 😊

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Dec 7, 2016

The last test I added currently fails. But I believe it will stop failing once we merge #1953, once that is merged I'll rebase this.

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Dec 7, 2016

@erikbern and @ulzha , do you want to review? I'm kinda pushing luigi towards a functional immutable style favoring framework by suggesting this change. Perhaps a consequence of being a Haskell fan and recently eaten a lof of Guava. (literally, but I've also used the Java library :))

Currently, running externalize on an existing class or object will have
serious side effects. Like subsequently created objects from the
original passed in class will also be externalized.

I see two reasons we should allow for this (possibly) overly dynamic
behavior in both accepting classes and objects. First, novice users
don't pay attention to the difference, second, it still possible and it
will *seem* to work to pass in the class instead of the object. I was at
least tempted to without being sure if it was "correct". Instead let's
try to be soft on the users for this case.

Also document that luigi.task.externalize is flexible in the sense it
both accepts a class and an object.
@Tarrasch Tarrasch force-pushed the specify_externalize_behaviour_clearly branch from f8738f0 to 07bf8d1 Compare December 7, 2016 10:43
@erikbern
Copy link
Contributor

erikbern commented Dec 7, 2016

yeah i think this makes a lot of sense

@Tarrasch Tarrasch merged commit d1bf1d3 into spotify:master Dec 8, 2016
@Tarrasch Tarrasch deleted the specify_externalize_behaviour_clearly branch December 19, 2016 02:58
Tarrasch added a commit to Tarrasch/luigi that referenced this pull request Dec 21, 2016
Currently, running externalize on an existing class or object will have
serious side effects. Like subsequently created objects from the
original passed in class will also be externalized. This patch changes
the behavior to return a changed copy and not having as much side-effects.

Secondly, this patch officially declares this function to work on both
classes and objects.
I see two reasons we should allow for this (possibly) overly dynamic
behavior in both accepting classes and objects. First, novice users
don't pay attention to the difference, second, it still possible and it
will seem to work to pass in the class instead of the object. I was at
least tempted to without being sure if it was "correct". Instead let's
try to be soft on the users for this case.
kreczko pushed a commit to kreczko/luigi that referenced this pull request Mar 28, 2017
Currently, running externalize on an existing class or object will have
serious side effects. Like subsequently created objects from the
original passed in class will also be externalized. This patch changes
the behavior to return a changed copy and not having as much side-effects.

Secondly, this patch officially declares this function to work on both
classes and objects.
I see two reasons we should allow for this (possibly) overly dynamic
behavior in both accepting classes and objects. First, novice users
don't pay attention to the difference, second, it still possible and it
will seem to work to pass in the class instead of the object. I was at
least tempted to without being sure if it was "correct". Instead let's
try to be soft on the users for this case.
This was referenced Jun 29, 2022
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.

3 participants