Skip to content

Commit 939c2cd

Browse files
Fix postgresql_set module if single-value param contains comma in value (#400)
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
1 parent 3d30888 commit 939c2cd

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- postgresql_set - avoid wrong values for single-value parameters containing commas (https://github.com/ansible-collections/community.postgresql/pull/400).

plugins/modules/postgresql_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def param_set(cursor, module, name, value, context):
315315
if str(value).lower() == 'default':
316316
query = "ALTER SYSTEM SET %s = DEFAULT" % name
317317
else:
318-
if isinstance(value, str) and ',' in value:
318+
if isinstance(value, str) and ',' in value and not name.endswith(('_command', '_prefix')):
319319
# Issue https://github.com/ansible-collections/community.postgresql/issues/78
320320
# Change value from 'one, two, three' -> "'one','two','three'"
321321
value = ','.join(["'" + elem.strip() + "'" for elem in value.split(',')])

tests/integration/targets/postgresql_set/tasks/options_coverage.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
log_statement: mod
3131
track_functions: none
3232
shared_preload_libraries: 'pg_stat_statements, pgaudit'
33+
log_line_prefix: 'db=%d,user=%u,app=%a,client=%h '
3334

3435
# Check mode:
3536
- name: Set settings in check mode
@@ -59,3 +60,13 @@
5960
- assert:
6061
that:
6162
- result.stdout == "shared_preload_libraries = 'pg_stat_statements, pgaudit'"
63+
64+
# Test for single-value params with commas and spaces in value
65+
- name: Test single-value param with commas and spaces in value
66+
<<: *task_parameters
67+
shell: "grep log_line_prefix {{ pg_auto_conf }}"
68+
register: result
69+
70+
- assert:
71+
that:
72+
- result.stdout == "log_line_prefix = 'db=%d,user=%u,app=%a,client=%h '"

0 commit comments

Comments
 (0)