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

tickets/DM-33977 Fixes for ConfigurableActionStructField #655

Merged
merged 4 commits into from Mar 25, 2022

Conversation

natelust
Copy link
Contributor

This ticket fixes some assignment logic in ConfigurableActionStructField wherein a local copy of a ConfigurableActionStruct was not being made, leaving a dangling reference to a config object that goes out of scope.

This ticket also makes a change to stay in line with other pex_config fields wherein it takes other python classes that duck like a ConfigurableActionStructField as an argument in assigment.

Finally this ticket adds a verification that a string used in the dict update interface is a valid python identifier.

Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a unit test. Otherwise looks good, but fix the "assignements" typo in one of the commit messages, too.

@@ -237,6 +247,21 @@ def __set__(self, instance: Config,
if value is None or value == self.default:
value = self.StructClass(instance, self, value, at=at, label=label)
else:
# An actual value is being assgigned check for what it is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# An actual value is being assgigned check for what it is
# An actual value is being assigned, check for what it is

elif isinstance(value, (SimpleNamespace, Struct)):
# If this is a a python analogous container, we need to make
# a ConfigurableActionStruct initialized with this data
value = self.StructClass(instance, self, vars(value), at=at, label=label)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that the call to vars doesn't return any "special" attributes for either SimpleNamespace or Struct? Seems like something worth adding a test for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified it though with a few tests in python manually, but I will add a unit test to guard against behavior changes (especially in Struct)

@natelust natelust force-pushed the tickets/DM-33977 branch 2 times, most recently from 70dc373 to af701d9 Compare March 24, 2022 18:40
The ConfigurableActionStructField needs to be able to take
appropriate assignements and either make a copy, or default
construct an instance of ConfigurableActionStruct, otherwise
the reference to the field object is lost.
If one adds attributes through a configurable action struct
through the update interface it was possible to use a string
that was not a valid python variable name, only to fail later
when it was read or loaded through a config file. This validates
that the strings are appropriate identifiers.
Add unit tests to test the behaviors when assigning to a
ConfigurableActionStructField.
@natelust natelust merged commit eb29297 into main Mar 25, 2022
@natelust natelust deleted the tickets/DM-33977 branch March 25, 2022 14:49
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.

None yet

2 participants