#31400 closed Bug (fixed)
base.py returns TypeError when CONN_MAX_AGE is set in a Postgresql connection
Reported by: | danb4r | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Documentation | Version: | 3.0 |
Severity: | Normal | Keywords: | CONN_MAX_AGE, base.py, Postgresql |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Just did a clean Django 3.0.4
Python 3.6.9, install with
Postgresql Version: 10+190ubuntu0.1 via psycopg2 (2.8.4)
inside Windows Subsystem for Linux.
When I run:
python manage.py migrate
I get:
File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/backends/base/base.py", line 192, in connect self.close_at = None if max_age is None else time.monotonic() + max_age TypeError: unsupported operand type(s) for +: 'float' and 'str'
The error does not happen with CONN_MAX_AGE not set:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'django_p1_master', 'USER': 'django', 'PASSWORD': 'secret', 'HOST': '127.0.0.1', 'PORT': '5432', # 'CONN_MAX_AGE': '600', } }
Full error stack:
(venv-django_p1) vmuser@REDBEAST:/mnt/c/usr/workspace/django_p1/dsite$ python manage.py migrate Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute output = self.handle(*args, **options) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 86, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__ self.build_graph() File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/migrations/loader.py", line 212, in build_graph self.applied_migrations = recorder.applied_migrations() File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 76, in applied_migrations if self.has_table(): File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 56, in has_table return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/backends/base/base.py", line 260, in cursor return self._cursor() File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/backends/base/base.py", line 236, in _cursor self.ensure_connection() File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection self.connect() File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) File "/mnt/c/usr/workspace/django_p1/venv-django_p1/lib/python3.6/site-packages/django/db/backends/base/base.py", line 192, in connect self.close_at = None if max_age is None else time.monotonic() + max_age TypeError: unsupported operand type(s) for +: 'float' and 'str'
Change History (6)
comment:1 by , 5 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 5 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Easy pickings: | set |
comment:3 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Pretty sure this is due to the fact you use a
str
('0'
) instead of anint
(0
) to defineCONN_MAX_AGE
.Accepting on the basis that the documentation could be adjusted to mention a positive
int
must be provided instead of the apparently too vague number term.