-
Notifications
You must be signed in to change notification settings - Fork 198
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
Allow the usage of lambdas for InputPort
default values
#3465
Allow the usage of lambdas for InputPort
default values
#3465
Conversation
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.
thanks @sphuber for this fix!
a few minor comments/questions.
Also, consider to at least reference the two other related issues that we saw yesterday (about resetting the DB during tests).
Ah, I see @chrisjsewell has me beat by 1 minute ;-) |
4e41d19
to
9574b41
Compare
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.
thanks @sphuber !
This is made possible by upgrading `plumpy` to version `0.14.3`. This functionality is useful to define defaults that should change at each invocation, for example the generation of a seed. However, it also provides a way to avoid the issues that arise when defining a default to be an instance of a `Node`. Since a node instance is always regarded as a mutable type by python, regardless whether it is stored or not, it can cause unexpected behavior. For example when the node appointed to the default value of a port is deleted in the database, the memory instance remains and points to a no longer existing database row. The next time it is accessed an exception will be thrown. Using a lambda avoids this problem.
9574b41
to
30a4a3f
Compare
Fixes #1604
This is made possible by upgrading
plumpy
to version0.14.3
. Thisfunctionality is useful to define defaults that should change at each
invocation, for example the generation of a seed. However, it also
provides a way to avoid the issues that arise when defining a default to
be an instance of a
Node
. Since a node instance is always regarded asa mutable type by python, regardless whether it is stored or not, it can
cause unexpected behavior. For example when the node appointed to the
default value of a port is deleted in the database, the memory instance
remains and points to a no longer existing database row. The next time
it is accessed an exception will be thrown. Using a lambda avoids this
problem.
Edit: this will also address #2515 and #3143 indirectly. It will still require users to replace mutable defaults with lambdas. Therefore I prefer to close them in a separate PR where the
InputPort
constructor implementation will warn when mutable values are specified for the port's default