Skip to content

Commit

Permalink
fix: parse options with numerical values as int (#225)
Browse files Browse the repository at this point in the history
* fix: parse options with numerical values as int

fixes #222

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
estahn and pre-commit-ci[bot] committed Aug 15, 2023
1 parent 9b0f325 commit 13be1aa
Show file tree
Hide file tree
Showing 2 changed files with 11 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
7 changes: 7 additions & 0 deletions tests/test_dj_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,13 @@ 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 13be1aa

Please sign in to comment.