ruby-pwsh
ruby-pwsh copied to clipboard
Timestamp value does not accept string as input
Describe the Bug
When providing a timestamp formatted string to a parameter that requires Timestamp type, it throws expects a value of type Undef or Timestamp, got String
Expected Behavior
The string should be accepted, then parsed into Timestamp.
Steps to Reproduce
Using the module computermanagementdsc : https://forge.puppet.com/modules/dsc/computermanagementdsc/readme
Using the resource dsc_scheduledtask
dsc_scheduledtask { "my_task":
dsc_ensure => present,
dsc_enable => true,
dsc_taskname => "my_task",
dsc_actionexecutable => 'ping.exe',
dsc_actionarguments => "localhost",
dsc_actionworkingpath => '',
dsc_scheduletype => 'daily',
dsc_starttime => '2024-06-19T22:00:00',
dsc_daysinterval => 1,
}
(Please note I tried a few different string format, but it always ends up with the same error)
Puppet run output:
Error: Failed to apply catalog: Parameter dsc_starttime failed on Dsc_scheduledtask[my_task]: dsc_scheduledtask.dsc_starttime expects a value of type Undef or Timestamp, got String
Environment
- Version puppet 7.23
- Platform Windows 2022
Additional Context
So I spent some time trying to debug the issue.
I looked at dsc_base_provider.rb source code and the code added with this PR : https://github.com/puppetlabs/ruby-pwsh/issues/57 is working fine as far as I can tell.
The type comparison seems to be done elsewhere, but I can't find it.
I also tried to force timestamp time with Timestamp.new()
but received the error
Error: Failed to apply catalog: Parameter dsc_starttime failed on Dsc_scheduledtask[my_task]: dsc_scheduledtask.dsc_starttime expects a value of type Undef or Timestamp, got Type[Timestamp]
The dsc_starttime parameter is defined as this in the module:
dsc_starttime: {
type: 'Optional[Timestamp]',
desc: 'The time of day this task should start at - defaults to 12:00 AM. Not valid for AtLogon and AtStartup tasks.',
mandatory_for_get: false,
mandatory_for_set: false,
mof_type: 'DateTime',
mof_is_embedded: false,
},
I tried to modify with Optional[String]
and Variant[Timestamp, String, Undef]
but this raised other issues and seems to be a wrong hack.
So far I do not have much more idea on what to do