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

(IAC-1657) Fix for invalid DateTime value error in invoke_get_method #169

Merged
merged 1 commit into from
Jun 24, 2021

Conversation

david22swan
Copy link
Member

@david22swan david22swan commented Jun 23, 2021

Fix has been put in place so that if the returned DateTime is nil it is not parsed and is instead returned as is.
In addition, if the parse ever fails the error is caught and outputted into the context, with nil being returned.

@david22swan david22swan requested a review from a team as a code owner June 23, 2021 14:43
Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Can we get a minimal unit test to validate this behavior? Otherwise, looks good!

@david22swan david22swan force-pushed the IAC-1657/main/nil_fix branch 3 times, most recently from df9687c to f7aa5bd Compare June 23, 2021 16:59
@david22swan david22swan force-pushed the IAC-1657/main/nil_fix branch 3 times, most recently from 6f83bc4 to 4d4d2b5 Compare June 24, 2021 12:31
@david22swan david22swan changed the title (IAC-1657) Fix for nil value error in invoke_get_method (IAC-1657) Fix for invalid value error in invoke_get_method Jun 24, 2021
@david22swan david22swan changed the title (IAC-1657) Fix for invalid value error in invoke_get_method (IAC-1657) Fix for invalid DateTime value error in invoke_get_method Jun 24, 2021
@david22swan david22swan force-pushed the IAC-1657/main/nil_fix branch 2 times, most recently from 3ce14cf to fdfe644 Compare June 24, 2021 12:37
Comment on lines 310 to 316
begin
data[type_key] = Puppet::Pops::Time::Timestamp.parse(data[type_key]) if context.type.attributes[type_key][:mof_type] =~ /DateTime/i && !data[type_key].nil?
rescue ArgumentError, TypeError => e
# Catch any failures in the parse, output them to the context and then return nil
context.err("Value returned for DateTime (#{data[type_key].inspect}) failed to parse: #{e}")
return nil
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want the data[type_key] = assignment to the begin/rescue block itself;

As is, this implementation will attempt to assign the parsed output to the key and, if that errors, return nil for the entire resource.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, thought that was the desired result, have changed it now

end

context 'When the DateTime is an invalid string' do
let(:name_hash) { { name: 'foo', dsc_name: 'foo', dsc_time: '21000101' } }
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make it more obvious this is a bad string and make it foo or something

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1588 to 1593

context 'When a'
it 'casts the formatted timestamp string to DateTime in the property hash' do
expect(date_time).to receive(:format).and_return('2100-01-01')
expect(result).to match(/datetime = \[DateTime\]'2100-01-01'/)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it ended up in the wrong place?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops

Fix has been put in place so that if the returned DateTime is nil it is not parsed and is instead returned as is.
In addition, if the parse ever fails the error is caught and outputted into the context, with nil being returned.
@michaeltlombardi michaeltlombardi merged commit 0452861 into puppetlabs:main Jun 24, 2021
@david22swan david22swan deleted the IAC-1657/main/nil_fix branch June 24, 2021 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants