PowerShell / DSC

This repo is for the DSC v3 project
MIT License
199 stars 28 forks source link

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

Open SteveL-MSFT opened 1 month ago

SteveL-MSFT commented 1 month ago

Prerequisites

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

michaeltlombardi commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

@michaeltlombardi just close this as resolved once documented