-
Notifications
You must be signed in to change notification settings - Fork 387
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: overwrite attribute values when not mergeable #1952
base: master
Are you sure you want to change the base?
Conversation
1a675a4
to
06fe94e
Compare
merger/merger.go
Outdated
} | ||
} | ||
|
||
isManaged := func(r *rule.Rule, attr string) bool { | ||
// Name and visibility are uniquely managed by gazelle. | ||
if attr == "name" || attr == "visibility" { |
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.
I actually don't think visibility
should be here but it causes too many changes in this repo atm. I think those changes are actually correct but they could be breaking such as reducing the visibility of //internal/...
.
06fe94e
to
5a35779
Compare
5a35779
to
697c5bf
Compare
23e8768
to
40bd8f4
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.
@tyler-french Could you test this at Uber?
rule/merge.go
Outdated
@@ -41,6 +41,9 @@ import ( | |||
// marked with a "# keep" comment, values in the attribute not marked with | |||
// a "# keep" comment will be dropped. If the attribute is empty afterward, | |||
// it will be deleted. | |||
// | |||
// If src has an attribute not present in 'mergeable' and not marked with a |
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.
Should this be
// If src has an attribute not present in 'mergeable' and not marked with a | |
// If dst has an attribute not present in 'mergeable' and not marked with a |
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.
I think this comment is correct as-is, although maybe confusing.
This is pointing out that attributes in src
will overwrite those in dst
if they are unknown and the value in dst
is not marked as # keep
.
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.
I've updated the comment a bit. See the fixup commits.
40bd8f4
to
e710945
Compare
08ca365
to
02d0808
Compare
I'm seeing 1000s of build files behaving differently, need to dig a bit deeper. Please hold off on merging for now |
@tyler-french what types of changes are you seeing? Are effected attributes in the |
@tyler-french have you had a chance to look at this? I don't understand why you'd ever want |
@tyler-french any news on this? We've been waiting for this fix at Adobe. |
The main issues we are seeing are:
I will try to make reproductions with public code sometime soon |
Are those changes all in rules_go targets or in custom languages you have? |
02d0808
to
87ba5e7
Compare
@tyler-french any updates here? Even just ideas for tests I could write to reproduce the issues you're finding... |
@tyler-french I'm trying to understand what's going on here... it really sounds like all the issues you're seeing would be gazelle respecting When should a |
The behavior that we depend on (for non-mergable attributes) is: The issue here is that we have many attributes that are supplied by a user, and the understanding is that gazelle is used to generate these attributes if they don't exist, but once they do exist, gazelle doesn't have the "permission" to merge/overwrite them, since they are marked as not mergeable. This is particularly needed/required when the gazelle plugin is not necessarily deterministic (e.g. an unsorted list), that way, we don't have to worry about gazelle overwriting an attribute when the value already exists, if the attribute is not mergeable. I think the solution here is that we should have a separate @linzhp do you have any thoughts? |
So, I guess another option is we address the non-determinism in these extensions and also add So it's more of a question of either: is changing the accepted behavior of non-mergable attributes risky? and/or is there a way we can alleviate issues that arise from people who depend on this behavior. |
There are 3 types of attributes:
This PR removes the support of Type 2. As you found out, you have to make a special case for |
My intention was to expand the "default values" scenario (point 2) to allow languages to decide the default vs override behaviour, where today gazelle forces the default behaviour.
The primary scenario I had was gazelle only managing attributes if a user opts-in, and otherwise letting the user do it manually (without needing The second use case I had was a feature where the attributes aren't known at compile time, maybe they come from directives or a config file of some type etc. If a user changes those directives or config files the attributes might need to change. |
Regarding letting languages decide on default vs overwriting attributes... This PR allows languages to make that decision, but we could also add something such as Or to avoid changing existing Note that |
According to the doc here: Lines 35 to 38 in 6699394
and the implementation here: Lines 108 to 110 in 6699394
string and boolean (and other "scalar" values) attributes are overridden by Gazelle if you declare them as Can you try declaring those attributes are |
Yeah, I understand the gazelle "mergeable" doesn't necessarily mean it will be merged. I think of it more as being "managed by gazelle" (which includes merge logic for non-primitives,
That's what I have done to workaround the issue this PR is "fixing". It just means I need a workaround to maintain the existing values when I don't want gazelle to be managing those attributes. |
I don't think removing the support of Type 2 attributes is fixing an issue. You just need to make them Type 3, which is already supported. Like you noted above, you will have to find another workaround if you remove the Type 2 support in order to maintain existing values. |
This PR simply adds the ability to set an attribute without marking it as mergeable. This does not remove any functionality. IMO if you want "default values" (type 2) then you should only set that default value if the attribute does not already have a value. Isn't that the definition of a default value? |
I have a workaround to accomplish what I'm looking for, but this use case seemed standard enough I thought a workaround shouldn't be required. If we don't want to change existing behaviour we could add this functionality another way. If we don't want to add this functionality we can close this PR. |
Fix #1962
What type of PR is this?
What package or component does this PR mostly affect?
What does this PR do? Why is it needed?
Allow updating non-mergeable/resolveable attributes.
Which issues(s) does this PR fix?
Fixes #1962
Other notes for review