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

Duplicates allowed for parameters and values (or any HashMap) #510

Open
3 tasks done
SteveL-MSFT opened this issue Aug 3, 2024 · 3 comments
Open
3 tasks done

Duplicates allowed for parameters and values (or any HashMap) #510

SteveL-MSFT opened this issue Aug 3, 2024 · 3 comments
Assignees
Labels
Doc-Impact Issue-Bug Something isn't working

Comments

@SteveL-MSFT
Copy link
Member

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Summary

Due to default serde behavior, duplicates in deserializing a HashMap is not an error and last one wins. There is another crate serde_with that has a macro that prevents dupes, but it doesn't work if the property is an Option<>. Tried a few ways to resolve this, but couldn't find a solutiont hat doesn't include implementing a custom deserializer. Deferring this work.

Steps to reproduce

$configYaml = @'
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
variables:
  myVariable: foo
  myVariable: bar
resources:
- name: test
  type: Test/Echo
  properties:
    output: "[variables('myVariable')]"
'@

dsc config get -d $configYaml

Expected behavior

Should error that `myVariable` is defined more than once

Actual behavior

`myVariable` takes the last set value

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.0-preview.3
PSEdition                      Core
GitCommitId                    7.5.0-preview.3
OS                             Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

dsc 3.0.0-preview.8

Visuals

No response

@SteveL-MSFT SteveL-MSFT added the Issue-Bug Something isn't working label Aug 3, 2024
@michaeltlombardi
Copy link
Collaborator

This could be resolved okay with a note in the documentation - fwiw, users who are defining their configuration documents in VS Code with the YAML extension will get author-time feedback that an object can't define the same property twice, so even though DSC isn't currently raising an error, the user has some way to know that defining the same key twice in an object isn't supported.

@SteveL-MSFT
Copy link
Member Author

Agree this could just be doc'd so we can focus on other items. I already spent too much time trying to figure out how to get it to not accept dupes, but existing solutions I found only worked if it wasn't an Option<> which is needed in our case.

@SteveL-MSFT
Copy link
Member Author

@michaeltlombardi just close this as resolved once documented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Doc-Impact Issue-Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants