Skip to content

Fix postgresql::default() return value for unknown parameters #1530

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 2 commits into from
Oct 12, 2023

Conversation

smortex
Copy link
Collaborator

@smortex smortex commented Oct 11, 2023

When calling postgresql::default() with a name that has no corresponding parameter, the function returns the string "postgresql::globals::" which is probably not intended given the comment above the code.

The usage of pick seems to indicate that an exception should be raised when a parameter is not found in params nor globals.pp, so adjust the code accordingly.

@smortex smortex force-pushed the fix-postgresql_default branch 2 times, most recently from 9ce58b1 to 587e488 Compare October 11, 2023 19:13
When calling `postgresql::default()` with a name that has no corresponding
parameter, the function returns the string
"postgresql::globals::<parameter-name>" which is probably not intended
given the comment above the code.

The usage of pick seems to indicate that an exception should be raised
when a parameter is not found in `params` nor `globals.pp`, so adjust
the code accordingly.
`postgresql::params` inherits from `postgresql::globals` so any variable
defined in `postgresql::globals` can be accessed by reading it from
`postgresql::params`, making it redundant to check both.
diff --git a/functions/default.pp b/functions/default.pp
index e36610b..41b5006 100644
--- a/functions/default.pp
+++ b/functions/default.pp
@@ -8,8 +8,7 @@ function postgresql::default(
 ) {
   include postgresql::params

-  #search for the variable name in params first
-  #then fall back to globals if not found
-  pick(getvar("postgresql::params::${parameter_name}"),
-       getvar("postgresql::globals::${parameter_name}"))
+  # Search for the variable name in params.
+  # params inherits from globals, so it will also catch these variables.
+  pick(getvar("postgresql::params::${parameter_name}"))
 }
@smortex smortex force-pushed the fix-postgresql_default branch from 587e488 to 6cb50cb Compare October 11, 2023 19:17
@smortex smortex marked this pull request as ready for review October 11, 2023 21:18
@Ramesh7 Ramesh7 merged commit e1c3a24 into main Oct 12, 2023
@Ramesh7 Ramesh7 deleted the fix-postgresql_default branch October 12, 2023 11:29
@bastelfreak bastelfreak mentioned this pull request Oct 12, 2023
3 tasks
"postgresql::globals::${parameter_name}")
# Search for the variable name in params.
# params inherits from globals, so it will also catch these variables.
pick(getvar("postgresql::params::${parameter_name}"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Late to the party, but what's the point of using pick() with a single parameter? Isn't just getvar() the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

getvar('nothing_here') returns undef. Since pick was already there, I assumed we wanted to have a strong failure with an exception in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspected that, but good to hear that explicitly.

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.

7 participants