Skip to content

Allow empty string value for config entries #1603

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/server/config_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
define postgresql::server::config_entry (
Enum['present', 'absent'] $ensure = 'present',
String[1] $key = $name,
Optional[Variant[String[1], Numeric, Array[String[1]]]] $value = undef,
Optional[Variant[String, Numeric, Array[String[1]]]] $value = undef,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the array also allow empty strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not aware of a use-case where an array would contain empty string values.

But I am not even sure if array values make sense for Postgres config entries, because it seems to use just (quoted) strings, integers, floats and booleans (https://www.postgresql.org/docs/current/config-setting.html#CONFIG-SETTING-NAMES-VALUES). And from quickly looking at the postgresql_conf provider I don't immediately see where/how it even handles array values? But in any case, I don't think we need to touch this part of the functionality here. Just support for single, empty string values would be nice :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

That may actually be a regression introduced in 179472b. It was added in 36674b3 but contain any description. #1434 does point to listen_addresses and now I wonder if that functionality actually works now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it seems the accepted data types of $value were changed to include Array[String[1]], and the "parsed" provider was replaced by a "ruby" provider, but there doesn't seem to have been any code added to actually handle such array values. The parsed provider had something like h[:value].join(', ') when h[:value] was an array, but I see no equivalent in the ruby provider.

But I suppose this discussion is best moved elsewhere, probably to its own bug report?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, it seems the accepted data types of $value were changed to include Array[String[1]], and the "parsed" provider was replaced by a "ruby" provider, but there doesn't seem to have been any code added to actually handle such array values. The parsed provider had something like h[:value].join(', ') when h[:value] was an array, but I see no equivalent in the ruby provider.

If the implementation is h[:value].join(', ') then an empty array should result in an empty string and allowing empty strings within the array doesn't make sense. It'd result in , which is probably never valid. In other words, consider my comments addressed.

But I suppose this discussion is best moved elsewhere, probably to its own bug report?

Yes, agreed.

Stdlib::Absolutepath $path = $postgresql::server::postgresql_conf_path,
Optional[String[1]] $comment = undef,
String[1] $instance_name = 'main',
Expand Down
16 changes: 16 additions & 0 deletions spec/defines/server/config_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,20 @@
.that_notifies('Postgresql::Server::Instance::Service[main]')
end
end

# Example use case for empty values: using transaction-bound session
# variables, like `SET LOCAL awesome_app.tenant_id = 92834` requires the
# variable to be defined in postgresql.conf and initialised with a default
# value (at least for PostgreSQL 13 and older, possibly also in newer
# versions). The default value can (and sometimes, depending on the
# application should) be empty.
context 'set a config entry value to the empty string' do
let(:params) { { ensure: 'present', name: 'mydb.app_param', value: '' } }

it 'sets value to the empty string' do
expect(subject).to contain_postgresql_conf('mydb.app_param').with(
name: 'mydb.app_param',
value: '')
end
end
end
Loading