[Django] #35006: Django db_table_comment with sqlite database

8 views
Skip to first unread message

Django

unread,
Nov 30, 2023, 2:42:21 AM11/30/23
to django-...@googlegroups.com
#35006: Django db_table_comment with sqlite database
--------------------------------------+-----------------------------------
Reporter: FeroxTL | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Keywords: sqlite migrations
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+-----------------------------------
It seems that I have found a bug in all 4.2+ versions of Django (including
main branch and 5.0rc). I made a repo with steps to reproduce and full
description of the bug – GitHub - FeroxTL/django-sqlite-bug 3 . Long story
short: sqlite does not support comments, but when you change (not create)
`Meta.db_table_comment` sqlite backend
`django.db.backends.sqlite3.schema.DatabaseSchemaEditor` tries to generate
COMMENT sql and it obviously falls.


{{{
$./manage.py migrate
System check identified some issues:

WARNINGS:
question.QuestionThree: (models.W046) SQLite does not support comments on
tables (db_table_comment).
Operations to perform:
Apply all migrations: admin, auth, contenttypes, question, sessions
Running migrations:
Applying question.0001_initial... OK
Applying question.0002_alter_questionthree_table_comment...Traceback
(most recent call last):
File "env/lib/python3.10/site-packages/django/db/backends/utils.py",
line 89, in _execute
return self.cursor.execute(sql, params)
File "env/lib/python3.10/site-
packages/django/db/backends/sqlite3/base.py", line 328, in execute
return super().execute(query, params)
sqlite3.OperationalError: near "COMMENT": syntax error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "proj/./manage.py", line 22, in <module>
main()
File "proj/./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "env/lib/python3.10/site-
packages/django/core/management/__init__.py", line 442, in
execute_from_command_line
utility.execute()
File "env/lib/python3.10/site-
packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "env/lib/python3.10/site-packages/django/core/management/base.py",
line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "env/lib/python3.10/site-packages/django/core/management/base.py",
line 458, in execute
output = self.handle(*args, **options)
File "env/lib/python3.10/site-packages/django/core/management/base.py",
line 106, in wrapper
res = handle_func(*args, **kwargs)
File "env/lib/python3.10/site-
packages/django/core/management/commands/migrate.py", line 356, in handle
post_migrate_state = executor.migrate(
File "env/lib/python3.10/site-
packages/django/db/migrations/executor.py", line 135, in migrate
state = self._migrate_all_forwards(
File "env/lib/python3.10/site-
packages/django/db/migrations/executor.py", line 167, in
_migrate_all_forwards
state = self.apply_migration(
File "env/lib/python3.10/site-
packages/django/db/migrations/executor.py", line 252, in apply_migration
state = migration.apply(state, schema_editor)
File "env/lib/python3.10/site-
packages/django/db/migrations/migration.py", line 132, in apply
operation.database_forwards(
File "env/lib/python3.10/site-
packages/django/db/migrations/operations/models.py", line 610, in
database_forwards
schema_editor.alter_db_table_comment(
File "env/lib/python3.10/site-
packages/django/db/backends/base/schema.py", line 640, in
alter_db_table_comment
self.execute(
File "env/lib/python3.10/site-
packages/django/db/backends/base/schema.py", line 201, in execute
cursor.execute(sql, params)
File "env/lib/python3.10/site-packages/django/db/backends/utils.py",
line 102, in execute
return super().execute(sql, params)
File "env/lib/python3.10/site-packages/django/db/backends/utils.py",
line 67, in execute
return self._execute_with_wrappers(
File "env/lib/python3.10/site-packages/django/db/backends/utils.py",
line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
File "env/lib/python3.10/site-packages/django/db/backends/utils.py",
line 84, in _execute
with self.db.wrap_database_errors:
File "env/lib/python3.10/site-packages/django/db/utils.py", line 91, in
__exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "env/lib/python3.10/site-packages/django/db/backends/utils.py",
line 89, in _execute
return self.cursor.execute(sql, params)
File "env/lib/python3.10/site-
packages/django/db/backends/sqlite3/base.py", line 328, in execute
return super().execute(query, params)
django.db.utils.OperationalError: near "COMMENT": syntax error
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/35006>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 30, 2023, 2:44:01 AM11/30/23
to django-...@googlegroups.com
#35006: Django db_table_comment with sqlite database
-----------------------------------+--------------------------------------

Reporter: FeroxTL | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Normal | Resolution:

Keywords: sqlite migrations | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Description changed by FeroxTL:

Old description:

New description:

It seems that I have found a bug in all 4.2+ versions of Django (including
main branch and 5.0rc). I made a repo with steps to reproduce and full

description of the bug – https://github.com/FeroxTL/django-sqlite-bug .

--

--
Ticket URL: <https://code.djangoproject.com/ticket/35006#comment:1>

Django

unread,
Nov 30, 2023, 2:55:50 AM11/30/23
to django-...@googlegroups.com
#35006: Django db_table_comment with sqlite database
-----------------------------------+------------------------------------
Reporter: FeroxTL | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: dev
Severity: Release blocker | Resolution:
Keywords: sqlite migrations | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by David Sanders):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report 🏆

--
Ticket URL: <https://code.djangoproject.com/ticket/35006#comment:2>

Reply all
Reply to author
Forward
0 new messages