Skip to content

Commit

Permalink
fix: Make pretty_to_bytes return IP addresses as is, instead of throw…
Browse files Browse the repository at this point in the history
…ing ValueError (#422)

Co-authored-by: Sverre H. Huseby <sverre.huseby@statnett.no>
  • Loading branch information
sverrehu and sverrehu committed Mar 8, 2023
1 parent 1830276 commit 04c04c4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- postgresql_set - avoid throwing ValueError for IP addresses and other values that may look like a number, but which are not (https://github.com/ansible-collections/community.postgresql/pull/422).
6 changes: 5 additions & 1 deletion plugins/modules/postgresql_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ def pretty_to_bytes(pretty_val):
pretty_val = int(pretty_val)

except ValueError:
pretty_val = float(pretty_val)
try:
pretty_val = float(pretty_val)

except ValueError:
return pretty_val

return pretty_val

Expand Down
1 change: 1 addition & 0 deletions tests/unit/plugins/modules/test_postgresql_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
('100MB', 104857600),
('1GB', 1073741824),
('10GB', 10737418240),
('127.0.0.1', '127.0.0.1')
]
)
def test_pretty_to_bytes(input_, expected):
Expand Down

0 comments on commit 04c04c4

Please sign in to comment.