-
Notifications
You must be signed in to change notification settings - Fork 663
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
Missing Rule breaks due to hash collisions for dataclass MatchError #4297
Comments
mkdir -p "./vars/test"
cat << _EOF_ > "./vars/test/foo.yml"
---
CamelCaseIsBad: foo
ALL_CAPS_ARE_BAD_TOO: foo
_EOF_
cat << _EOF_ > "./vars/test/bar.yml"
---
CamelCaseIsBad: bar
ALL_CAPS_ARE_BAD_TOO: bar
_EOF_
ansible-lint --offline "./vars/test" That said, when running the following in addition, this issue seems to disappear. cat << _EOF_ > "./vars/test/bar.yml"
---
AnotherCamelCaseIsBad: bar
ANOTHER_ALL_CAPS_ARE_BAD_TOO: bar
_EOF_
ansible-lint --offline "./vars/test" |
@cavcrosby for the 2nd case you highlighted, it has to be exactly the same rule "description" being broken (which in the case of var naming requires to have the same variable name), otherwise the hash calculated will be different (the only thing not taking into account for the hash right now that we noticed was the filename, which causes the conflict between hashes if there are 2 rules broken with the same description, at the same line number, but in different files). |
Ahh, I see what you mean. I'll look into opening a PR for this sometime soon. |
Setting the filename for match_error has been removed because this will be done on MatchError instance creation via the __post_init__ method.
Setting the filename for match_error has been removed because this will be done on MatchError instance creation via the __post_init__ method.
Setting the filename for match_error has been removed because this will be done on MatchError instance creation via the __post_init__ method.
Setting the filename for match_error has been removed because this will be done on MatchError instance creation via the __post_init__ method.
Summary
Rule breaks with the same exact message and line number, but different filename are missing due to a hash collision.
Issue Type
OS / ENVIRONMENT
ansible-lint version 24.7.0
STEPS TO REPRODUCE
The MatchError data class has the
unsafe_hash=True
, which generates automatically a hash function based on the members of the class, however the fieldfilename
is non-existent (not defined) in thedataclass
, it is added at a later stage (see: var_naming.py#L204) and then all the errors are added to a set (see: runner.py#L682). Due to thefilename
member being non-existent at the class definition, the hash function does not take into account thefilename
and cause collisions if you have the same exact rule break in another file at the same line number.Desired Behavior
The same rule break happening in a different file on the same line number should be recorded properly as different rule break.
Actual Behavior
Simplified code example of the reproducible issue we are experiencing:
Potential fix:
The text was updated successfully, but these errors were encountered: