Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#27180 closed Bug (fixed)

Check for sql_mode fails during migration with special database connections

Reported by: Markus Gerards Owned by: nobody
Component: Database layer (models, ORM) Version: 1.10
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I believe I found again a bug regarding some special database connections (like #26991):

Running migrate raises this error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 342, in execute
    self.check()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 61, in _run_checks
    issues = run_checks(tags=[Tags.database])
  File "/usr/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python2.7/site-packages/django/core/checks/database.py", line 10, in check_database_backends
    issues.extend(conn.validation.check(**kwargs))
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 9, in check
    issues.extend(self._check_sql_mode(**kwargs))
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py", line 16, in _check_sql_mode
    modes = set(sql_mode[0].split(','))
TypeError: 'NoneType' object has no attribute '__getitem__'

The reason is, that SELECT @@sql_mode returns no results in my special case.

Just a little side note: migrate runs database checks against all database connections, no matter if a database is selected via the --database parameter or if migrations are not allowed because of a database router. I'm not quite sure if this works as intended.

Attachments (1)

27180.diff (1.1 KB) - added by Markus Gerards 7 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 7 years ago by Tim Graham

Component: MigrationsDatabase layer (models, ORM)
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by Claude Paroz

Could we know a bit more about that special database connection, please?

comment:3 Changed 7 years ago by Tim Graham

From #26991, "I'm connecting via MySQL to an sphinxsearch database. It basically uses the MySQL query language but has some special features."

comment:4 Changed 7 years ago by Claude Paroz

I'm wondering if we should continue this way with this special usage. Wouldn't the right solution to subclass the MySQL backend and adapt the checks?

comment:5 Changed 7 years ago by Tim Graham

I'm not sure how much ongoing work it would add to support this but if the backend has otherwise been usable since some old version of Django, then it seem reasonable to try to continue that as long as only minor changes are needed. We could also demote such issues from release blockers and require people using these special connections to submit patches themselves.

Changed 7 years ago by Markus Gerards

Attachment: 27180.diff added

comment:6 in reply to:  4 Changed 7 years ago by Markus Gerards

Replying to claudep:

I'm wondering if we should continue this way with this special usage. Wouldn't the right solution to subclass the MySQL backend and adapt the checks?

This is for sure no problem for us if we run into another problems in future. But in this specific case I believe there can be other cases where this error could occur. I've attached a little patch, that works for us.

comment:7 Changed 7 years ago by Claude Paroz

@gerricom: thanks for the patch, could you provide it as a pull request on Github?

comment:8 Changed 7 years ago by Markus Gerards

comment:9 Changed 7 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 2b64ff68:

Fixed #27180 -- Fixed a crash in MySQL checks where SELECT @@sql_mode doesn't return a result.

comment:10 Changed 7 years ago by Tim Graham <timograham@…>

In baa1790b:

[1.10.x] Fixed #27180 -- Fixed a crash in MySQL checks where SELECT @@sql_mode doesn't return a result.

Backport of 2b64ff68cc375b5688174b4087bf44be9edd2558 from master

Note: See TracTickets for help on using tickets.
Back to Top