Skip to content

Hidden properties in class-based resource are added to result and trace log #832

Closed
@johlju

Description

@johlju

Prerequisites

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

Summary

I am experiencing a problem with hidden variables in class-based resource are included in result and trace logs from the Get operation. I think only actual DSC properties should be added to the result and trace log, but these internal variables are actually being included in the result - and in the trace log in a way that make it look like they are DSC properties, which could causes confusion.

The issue #363 track this but it doesn't seem to have been resolved by PR that was expected to resolve it.

Steps to reproduce

  1. Add a hidden property to any class-based resource.
  2. Run the command:
    dsc --trace-level trace resource get --resource MyModule/MyClassBasedResource --output-format json --input $jsonResourceParameters
  3. Watch the result and trace log output where it says jsonOutput={"result": ... } and see it has added hidden property to the output.

Real-world repro:

  1. Install latest module SqlServerDsc (that include the class-based resource) into the correct folder
  2. Run the following:
     $desiredParameters = @{
         InstanceName = 'PBIRS'
         AcceptLicensingTerms = $true
         Action = 'Install'
         MediaPath = '<Path to any existing executable on local machine>'
         InstallFolder = [System.IO.Path]::GetTempPath()
         Edition = 'Developer'
         SuppressRestart = $true
         VersionUpgrade = $true
     }
    
      dsc --trace-level trace resource get --resource SqlServerDsc/SqlRSSetup --output-format pretty-json --input ($desiredParameters | ConvertTo-Json -Compress)
  3. Watch the result and trace log output where it says jsonOutput={"result": ... } and see it has added hidden property to the output.
    It's also available here in the issue comment: Add integration test stage for DSCv3 dsccommunity/SqlServerDsc#2102 (comment)

Expected behavior

I would expect the result and trace log to only output the actual DSC properties as the result from the Get operation.

Actual behavior

# The result and trace log includes both the actual DSC properties but also internal properties that are shown as the result from the Get operation.
# Example output from a DebugDscEngine class-based resource wrongly returns the hidden properties localizedData, ExcludeDscProperties and FeatureOptionalEnums.
{
  "actualState": {
    "KeyProperty": "TEST_KEY_001",
    "MandatoryProperty": "CurrentMandatoryStateValue",
    "WriteProperty": "CurrentStateValue",
    "ReadProperty": "ReadOnlyValue_20250524_084107",
    "localizedData": {
      "Debug_Modify_Completed": "Modify method completed for KeyProperty '{0}'.",
      "KeyProperty_Invalid": "The parameter KeyProperty cannot be null or empty.",
      "Debug_Modify_Property": "Modifying property '{0}' to value '{1}'.",
      "Getting_CurrentState": "Getting current state for DebugDscEngine resource with KeyProperty '{0}'.",
      "TestDesiredState": "Determining the current state for resource '{0}' using the key property '{1}'. (RB0002)",
      "Debug_AssertProperties_Completed": "AssertProperties method completed for KeyProperty '{0}'.",
      "Debug_GetCurrentState_Returning": "GetCurrentState method returning properties: {0}.",
      "Debug_NormalizeProperties_Called": "NormalizeProperties method called for KeyProperty '{0}' with properties: {1}.",
      "Debug_AssertProperties_Called": "AssertProperties method called for KeyProperty '{0}' with properties: {1}.",
      "SetDesiredState": "Setting the desired state for resource '{0}' using the key property '{1}'. (RB0003)",
      "Debug_NormalizeProperties_Completed": "NormalizeProperties method completed for KeyProperty '{0}'.",
      "NoPropertiesToSet": "All properties are in desired state. (RB0007)",
      "Debug_GetCurrentState_Called": "GetCurrentState method called for KeyProperty '{0}' with properties: {1}.",
      "InDesiredState": "The current state is the desired state. (RB0005)",
      "NotInDesiredState": "The current state is not the desired state. (RB0004)",
      "Debug_NormalizeProperties_Property": "Normalized property '{0}' to value '{1}'.",
      "SetProperty": "The property '{0}' will be set to '{1}'. (RB0006)",
      "MandatoryProperty_Invalid": "The parameter MandatoryProperty cannot be null or empty.",
      "Debug_Modify_Called": "Modify method called for KeyProperty '{0}' with properties to modify: {1}.",
      "ModifyMethodNotImplemented": "An override for the method Modify() is not implemented in the resource. (RB0008)",
      "GetCurrentState": "Getting the current state for resource '{0}' using the key property '{1}'. (RB0001)",
      "GetCurrentStateMethodNotImplemented": "An override for the method GetCurrentState() is not implemented in the resource. (RB0009)"
    },
    "ExcludeDscProperties": [
      "MandatoryProperty"
    ],
    "FeatureOptionalEnums": false
  }
}

Error details

Not applicable

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.7
PSEdition                      Core
GitCommitId                    7.4.7
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

3.1.0-preview.6

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions