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

Fix spec initializing copying wrong property #4108

Merged
merged 10 commits into from
Jun 20, 2024

Conversation

theunrepentantgeek
Copy link
Member

What this PR does / why we need it:

In #3805, @nojnhuh noticed that asoctl was initializing the type field on an imported AgentPool with the wrong value.

Investigation leads to the observation that properties with the same name don't necessarily have the same providence - not every Type field can be copied into another Type field.

Special notes for your reviewer:

There are two fixes.

The first is to check the origin of each property, skipping the assign-identically-named-properties step if the properties came from different places

The second fix is to use the path-of-origin of the remaining properties to match things up. This is complicated by the possibility that the property may be configurable - so we would have both Type and TypeFromConfig as candidates. We disambiguate these by doing a fast and loose compatibility check on the types, which seems good enough.

How does this PR make you feel:
gif

If applicable:

  • this PR contains tests

Copy link
Member

@matthchr matthchr left a comment

Choose a reason for hiding this comment

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

Nice!

path []astmodel.PropertyName,
) *TypedConversionEndpoint {
var builder strings.Builder
for i, name := range path {
Copy link
Member

Choose a reason for hiding this comment

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

minor: You could probably have used strings.Join here, though it would require transforming the path to strings first.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

// assign is a function that will be called for each matching property, with the source and destination endpoints
// for that property.
// Returns an error if any of the assignments fail.
func (builder *PropertyAssignmentFunctionBuilder) selectIdenticallyPathedProperties(
Copy link
Member

Choose a reason for hiding this comment

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

extremely minor:

Suggested change
func (builder *PropertyAssignmentFunctionBuilder) selectIdenticallyPathedProperties(
func (builder *PropertyAssignmentFunctionBuilder) selectPropertiesWithIdenticalPaths(

(avoids IdenticallyPathed which read weird to me. Not sure it's really all that much better.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@theunrepentantgeek theunrepentantgeek added this pull request to the merge queue Jun 19, 2024
@theunrepentantgeek theunrepentantgeek removed this pull request from the merge queue due to a manual request Jun 19, 2024
@matthchr
Copy link
Member

Seems some unit test failures @theunrepentantgeek

@theunrepentantgeek theunrepentantgeek added this pull request to the merge queue Jun 19, 2024
Merged via the queue into main with commit 1424557 Jun 20, 2024
8 checks passed
@theunrepentantgeek theunrepentantgeek deleted the fix/initialize-spec branch June 20, 2024 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants