Skip to content

Deprecate the validate_legacy() function #1353

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

Merged
merged 1 commit into from
May 15, 2023
Merged

Conversation

smortex
Copy link
Collaborator

@smortex smortex commented May 11, 2023

This is a follow-up to #1352 and in particular #1352 (comment).

I reproduce the content bellow so that we can discuss this, and provide an implementation.

Context

validate_legacy() was used with a data type and a validation function. If the value was matched by both the data type and the validation function, it produced no warning, otherwise it produced a warning if the new data type was matched but the legacy validation function was not accepting the value or an deprecation message if the data type was not matched but the legacy validation was accepted. The validation functions used are the ones being removed by this PR, so validate_legacy() needs to be taken care of.

The table bellow summarize the current behavior of validate_legacy():

Data Type Legacy function result
✔️ pass ✔️ pass ✔️ pass
✔️ pass ❌ fail ⚠️ notice (Accepting previously invalid value for target type)
❌ fail ✔️ pass ⚠️ deprecation(validate_legacy)
❌ fail ❌ fail ❌ fail

Assumptions

The last line (fail/fail) is not expected to be seen into the wild because the compilation failure makes modules unusable.

For the 3 first line, only the first one does not produce annoying deprecation warning / notice, so we expect that such issues have been fixed.

Proposal

Update the function to always emit a deprecation message, and only validate the value against the provided data type. The validation function is therefore completely ignored (but the function prototype is not changed for backwards compatibility).

The table bellow summarize the proposed behavior of validate_legacy():

Data Type Legacy function result
✔️ pass ❔ ignored ⚠️ deprecation(replace validate_legacy() with data type)
❌ fail ❔ ignored ❌ fail

@smortex smortex requested review from a team, alexjfisher, b4ldr, bastelfreak and ekohl as code owners May 11, 2023 18:36
@puppet-community-rangefinder
Copy link

validate_legacy is a function

Breaking changes to this file MAY impact these 67 modules (near match):

This module is declared in 318 of 580 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

`validate_legacy()` was added to help migrating from the legacy
validation functions to the new Puppet data types which where not 100%
backward compatible with the previous validation (e.g. `'42'` was a
valid integer according to `validate_integer()` but indeed a String and
not an Integer when using data types.

The legacy validation functions have been removed from stdlib, so
`validate_legacy()` will now fail if it tries to run them.  But as
they produced deprecation warning, they are supposed to have already
been fixed.  For the sake of security, instead of removing
`validate_legacy()` now, deprecate it so that it is strictly equivalent
to validating using a data type, but also emits a warning.
@smortex smortex force-pushed the deprecate-validate-legacy branch from 3539d65 to 1bcbf87 Compare May 11, 2023 18:39
Copy link
Member

@david22swan david22swan left a comment

Choose a reason for hiding this comment

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

LGTM

Was just looking at this issue

Copy link
Contributor

@LukasAud LukasAud left a comment

Choose a reason for hiding this comment

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

LGTM

@LukasAud LukasAud merged commit 1ad1b1c into main May 15, 2023
@LukasAud LukasAud deleted the deprecate-validate-legacy branch May 15, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants