Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Option value connect_timeout returned as string instead of int #222

Closed
estahn opened this issue Jul 17, 2023 · 2 comments · Fixed by #225
Closed

Option value connect_timeout returned as string instead of int #222

estahn opened this issue Jul 17, 2023 · 2 comments · Fixed by #225

Comments

@estahn
Copy link
Contributor

estahn commented Jul 17, 2023

Version: 1.3.0 and 2.0.0

Example:

import dj_database_url

print(dj_database_url.parse("mysql://user:pw@127.0.0.1:15036/db?connect_timout=3"))

Returns:

{'NAME': 'db', 'USER': 'user', 'PASSWORD': 'pw', 'HOST': '127.0.0.1', 'PORT': 15036, 'CONN_MAX_AGE': 0, 'CONN_HEALTH_CHECKS': False, 'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {'connect_timout': '3'}}

Expected:

{'NAME': 'db', 'USER': 'user', 'PASSWORD': 'pw', 'HOST': '127.0.0.1', 'PORT': 15036, 'CONN_MAX_AGE': 0, 'CONN_HEALTH_CHECKS': False, 'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {'connect_timout': 3}}

Error:

  ...
  File ".venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 247, in get_new_connection
    connection = Database.connect(**conn_params)
  File ".venv/lib/python3.9/site-packages/MySQLdb/__init__.py", line 123, in Connect
    return Connection(*args, **kwargs)
  File ".venv/lib/python3.9/site-packages/MySQLdb/connections.py", line 185, in __init__
    super().__init__(*args, **kwargs2)
TypeError: an integer is required (got type str)

Suggested fix:

try:
   value = int(value)
except (TypeError, ValueError):
   value = value
estahn added a commit to estahn/dj-database-url that referenced this issue Aug 15, 2023
mattseymour pushed a commit that referenced this issue Aug 15, 2023
* 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>
@mattseymour
Copy link
Contributor

Going to start building a release for this now. v2.1.0

@estahn
Copy link
Contributor Author

estahn commented Aug 15, 2023

Awesome, thanks @mattseymour

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants