Skip to content

Commit

Permalink
fix: parse options with numerical values as int
Browse files Browse the repository at this point in the history
  • Loading branch information
estahn committed Aug 15, 2023
1 parent 9b0f325 commit a2ebd74
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dj_database_url/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ def parse(
options["ssl"] = {"ca": values[-1]}
continue

options[key] = values[-1]
try:
options[key] = int(values[-1])
except (TypeError, ValueError):
options[key] = values[-1]

if ssl_require:
options["sslmode"] = "require"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_dj_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ def test_ssl_require(self):
url = dj_database_url.config(ssl_require=True)
assert url["OPTIONS"] == {'sslmode': 'require'}

def test_options_int_values(self):
"""Ensure that options with integer values are parsed correctly."""
url = dj_database_url.parse("mysql://user:pw@127.0.0.1:15036/db?connect_timout=3")
assert url["OPTIONS"] == {'connect_timout': 3}


if __name__ == "__main__":
unittest.main()

0 comments on commit a2ebd74

Please # to comment.