Skip to content

Django 3.1: TypeError: sql_flush() takes 3 positional arguments but 4 were given #329

@jklemm

Description

@jklemm

Hi!

After upgrade from Django 3.0 to 3.1, running my tests using django-nose gives me this exception:

REUSE_DB=1 nosetests mypackage --with-fixture-bundling --with-parallel --with-xunit --verbosity=1

  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/django/core/management/commands/test.py", line 53, in handle
    failures = test_runner.run_tests(test_labels)
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/django_nose/runner.py", line 308, in run_tests
    result = self.run_suite(nose_argv)
  File "~/Repos/myrepo/test_utils/nose/__init__.py", line 52, in run_suite
    return super(MyNoseRunner, self).run_suite(nose_argv)
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/django_nose/runner.py", line 244, in run_suite
    nose.core.TestProgram(argv=nose_argv, exit=False,
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/nose/core.py", line 118, in __init__
    unittest.TestProgram.__init__(
  File "~/.pyenv/versions/3.9.11/lib/python3.9/unittest/main.py", line 101, in __init__
    self.runTests()
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/nose/core.py", line 207, in runTests
    result = self.testRunner.run(self.test)
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/nose/core.py", line 50, in run
    wrapper = self.config.plugins.prepareTest(test)
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/nose/plugins/manager.py", line 99, in __call__
    return self.call(*arg, **kw)
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/nose/plugins/manager.py", line 167, in simple
    result = meth(*arg, **kw)
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/django_nose/plugin.py", line 82, in prepareTest
    self.old_names = self.runner.setup_databases()
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/django_nose/runner.py", line 466, in setup_databases
    reset_statements = _mysql_reset_sequences(
  File "~/.virtualenvs/web-django31/lib/python3.9/site-packages/django_nose/runner.py", line 405, in _mysql_reset_sequences
    flush_statements = connection.ops.sql_flush(
TypeError: sql_flush() takes 3 positional arguments but 4 were given

The implementation of MyNoseRunner:

import re
from django_nose import NoseTestSuiteRunner


class MyNoseRunner(NoseTestSuiteRunner):
    def run_suite(self, nose_argv):
        stack = traceback.extract_stack()
        running_with_pycharm = any([re.findall('[Pp]y[cC]harm|pydev', str(item)) for item in stack])

        if running_with_pycharm:
            print('Apply PyCharm fix...\n')
            nose_argv[1] = convert_test_uri_to_nose_pattern(nose_argv[1])

        return super(MyNoseRunner, self).run_suite(nose_argv)

The versions of my local environment:


macOS Monterey 12.4
Apple M1

Python 3.9.11

Django==3.1.14
django-nose==1.4.7
nose==1.3.7
nose-parallel==0.4.0

I've found an issue on other repo and there is:

probably because the signature for sql_flush has changed (also in https://docs.djangoproject.com/en/3.1/releases/3.1/#backwards-incompatible-changes-in-3-1).

Compare
https://github.com/django/django/blob/3.0.9/django/db/backends/base/operations.py#L384
vs
https://github.com/django/django/blob/3.1/django/db/backends/base/operations.py#L392

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions