-
Notifications
You must be signed in to change notification settings - Fork 17
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
PortNamespace
: Make dynamic
apply recursively
#263
Conversation
@unkcpz This change is required for aiidateam/aiida-core#5954 So in order to provide the proper context, it may make sense to read through that |
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## support/0.21.x #263 +/- ##
===============================================
Coverage 90.82% 90.82%
===============================================
Files 21 21
Lines 2971 2971
===============================================
Hits 2698 2698
Misses 273 273 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
The `dynamic` attribute of a port namespace indicates whether it should accept ports that are not explicitly defined. This was mostly used during validation, when a dictionary of port values was matched against a given `PortNamespace`. This was, however, not being applied recursively _and_ only during validation. For example, given a dynamic portnamespace, validating a dictionary: { 'nested': { 'output': 'some_value' } } would pass validation without problems. However, the `Process.out` call that would actually attempt to attach the output to the process instance would call: self.spec().outputs.get_port(namespace_separator.join(namespace)) which would raise, since `get_port` would raise a `ValueError`: ValueError: port 'output' does not exist in port namespace 'nested' The problem is that the `nested` namespace is expected, because the top level namespace was marked as dynamic, however, it itself would not also be treated as dynamic and so attempting to retrieve `some_value` from the `nested` namespace, would trigger a `KeyError`. Here the logic in `PortNamespace.get_port` is updated to check in advance whether the port exists in the namespace, and if not the case _and_ the namespace is dynamic, the nested port namespace is created. The attributes of the new namespace are inherited from its parent namespace, making the `dynamic` attribute act recursively.
c5e2129
to
5d50128
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.
Looks good to me!
The `dynamic` attribute of a port namespace indicates whether it should accept ports that are not explicitly defined. This was mostly used during validation, when a dictionary of port values was matched against a given `PortNamespace`. This was, however, not being applied recursively _and_ only during validation. For example, given a dynamic portnamespace, validating a dictionary: { 'nested': { 'output': 'some_value' } } would pass validation without problems. However, the `Process.out` call that would actually attempt to attach the output to the process instance would call: self.spec().outputs.get_port(namespace_separator.join(namespace)) which would raise, since `get_port` would raise a `ValueError`: ValueError: port 'output' does not exist in port namespace 'nested' The problem is that the `nested` namespace is expected, because the top level namespace was marked as dynamic, however, it itself would not also be treated as dynamic and so attempting to retrieve `some_value` from the `nested` namespace, would trigger a `KeyError`. Here the logic in `PortNamespace.get_port` is updated to check in advance whether the port exists in the namespace, and if not the case _and_ the namespace is dynamic, the nested port namespace is created. The attributes of the new namespace are inherited from its parent namespace, making the `dynamic` attribute act recursively. Cherry-pick: 4c29f44
The `dynamic` attribute of a port namespace indicates whether it should accept ports that are not explicitly defined. This was mostly used during validation, when a dictionary of port values was matched against a given `PortNamespace`. This was, however, not being applied recursively _and_ only during validation. For example, given a dynamic portnamespace, validating a dictionary: { 'nested': { 'output': 'some_value' } } would pass validation without problems. However, the `Process.out` call that would actually attempt to attach the output to the process instance would call: self.spec().outputs.get_port(namespace_separator.join(namespace)) which would raise, since `get_port` would raise a `ValueError`: ValueError: port 'output' does not exist in port namespace 'nested' The problem is that the `nested` namespace is expected, because the top level namespace was marked as dynamic, however, it itself would not also be treated as dynamic and so attempting to retrieve `some_value` from the `nested` namespace, would trigger a `KeyError`. Here the logic in `PortNamespace.get_port` is updated to check in advance whether the port exists in the namespace, and if not the case _and_ the namespace is dynamic, the nested port namespace is created. The attributes of the new namespace are inherited from its parent namespace, making the `dynamic` attribute act recursively. Cherry-pick: 4c29f44
The
dynamic
attribute of a port namespace indicates whether it should accept ports that are not explicitly defined. This was mostly used during validation, when a dictionary of port values was matched against a givenPortNamespace
.This was, however, not being applied recursively and only during validation. For example, given a dynamic portnamespace, validating a dictionary:
would pass validation without problems. However, the
Process.out
call that would actually attempt to attach the output to the process instance would call:which would raise, since
get_port
would raise aValueError
:The problem is that the
nested
namespace is expected, because the top level namespace was marked as dynamic, however, it itself would not also be treated as dynamic and so attempting to retrievesome_value
from thenested
namespace, would trigger aKeyError
.Here the logic in
PortNamespace.get_port
is updated to check in advance whether the port exists in the namespace, and if not the case and the namespace is dynamic, the nested port namespace is created. The attributes of the new namespace are inherited from its parent namespace, making thedynamic
attribute act recursively.