Skip to content

Conversation

bertdawg76
Copy link
Collaborator

What does this PR do?

when grains.item returns a list, this removes duplicate entries in the list

What issues does this PR fix or reference?

Fixes #31427

Previous Behavior

Duplicate in list were returned

New Behavior

Duplicates in list not returned

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes/No

@bertdawg76 bertdawg76 requested a review from a team as a code owner August 26, 2025 20:49
@bertdawg76 bertdawg76 added Tests test:full Run the full test suite labels Aug 26, 2025
@bertdawg76 bertdawg76 self-assigned this Aug 26, 2025
@bertdawg76 bertdawg76 closed this Aug 26, 2025
@bertdawg76 bertdawg76 reopened this Aug 26, 2025
@bertdawg76 bertdawg76 changed the base branch from master to 3006.x August 26, 2025 21:04
@bertdawg76 bertdawg76 added this to the Sulfur v3006.15 milestone Aug 26, 2025
@twangboy twangboy removed the Tests label Aug 26, 2025
@dwoz
Copy link
Contributor

dwoz commented Aug 27, 2025

@bertdawg76 Does this change only remove duplicates from roles or any grains that have a list value?

Comment on lines +210 to +212
if isinstance(ret[arg], list):
unique_ret = list(dict.fromkeys(ret[arg]))
ret[arg] = unique_ret
Copy link
Contributor

@bdrx312 bdrx312 Aug 28, 2025

Choose a reason for hiding this comment

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

This does not seem correct as a change for any generic grain that has a list value. It is conceivable to me that a grain could intentionally have a list that has items that have the same value--especially with a custom grain. Nothing I have read states that the value of a grain must be a set of unique values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. The referenced issue relates to the state module adding duplicates, not the execution one listing duplicates.

It should have already been fixed in #31471 though, is it still an issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

#31471 itself seems to indicate that duplicate items in the list is unexpected behavior. I can't think of a scenario where it would be desirable. That being said, this PR does not seem to fix that issue.

@bertdawg76
Copy link
Collaborator Author

@dwoz it will remove duplicate values from any returned list, when the grain.item function is called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test:full Run the full test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

salt.states.grains.list_present adds duplicates names
5 participants