jazzband / django-redshift-backend

Redshift database backend for Django
Apache License 2.0
83 stars 47 forks source link

_create_index_sql() doesn't accept a keyword argument 'name' #92

Closed shimizukawa closed 2 years ago

shimizukawa commented 2 years ago

Problem

Procedure to reproduce the problem

python manage.py makemigrations testapp  # passed
python manage.py sqlmigrate testapp 0001  # error

Error logs / results

Traceback (most recent call last):
  File "/home/runner/work/django-redshift-backend/django-redshift-backend/examples/proj1/manage.py", line 22, in <module>
    main()
  File "/home/runner/work/django-redshift-backend/django-redshift-backend/examples/proj1/manage.py", line [18](https://github.com/jazzband/django-redshift-backend/runs/5176314949?check_suite_focus=true#step:6:18), in main
    execute_from_command_line(sys.argv)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/core/management/__init__.py", line 4[19](https://github.com/jazzband/django-redshift-backend/runs/5176314949?check_suite_focus=true#step:6:19), in execute_from_command_line
    utility.execute()
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/core/management/commands/sqlmigrate.py", line 29, in execute
    return super().execute(*args, **options)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/core/management/commands/sqlmigrate.py", line 65, in handle
    sql_statements = loader.collect_sql(plan)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/migrations/loader.py", line 349, in collect_sql
    state = migration.apply(state, schema_editor, collect_sql=True)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/migrations/operations/models.py", line 761, in database_forwards
    schema_editor.add_index(model, self.index)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/backends/postgresql/schema.py", line [21](https://github.com/jazzband/django-redshift-backend/runs/5176314949?check_suite_focus=true#step:6:21)8, in add_index
    self.execute(index.create_sql(model, self, concurrently=concurrently), params=None)
  File "/opt/hostedtoolcache/Python/3.10.2/x64/lib/python3.10/site-packages/django/db/models/indexes.py", line 111, in create_sql
    return schema_editor._create_index_sql(
TypeError: DatabaseSchemaEditor._create_index_sql() got an unexpected keyword argument 'name'

Add a example project for testing and showcase · jazzband/django-redshift-backend@e81c87d

Expected results

No errors for sqlmigrate

Environment info

shimizukawa commented 2 years ago

caused by: https://github.com/django/django/commit/831358f23d545b8dba017c6b26bd295ba9f6c17d#diff-f7637259acc1ecbb74910a7df2879cae5f3209d7a87ab0ad06dbd594b27f1831R892

Since Django-2.0, django/db/backends/base/schema.py has been accepted extra keyword arguments:

    def _create_index_sql(self, model, fields, *, name=None, suffix='', using='',
                          db_tablespace=None, col_suffixes=(), sql=None):

And Django-3.2.12 also accepts too. https://github.com/django/django/blob/fdf209eab8949ddc345aa0212b349c79fc6fdebb/django/db/backends/postgresql/schema.py#L227-L231

    def _create_index_sql(
        self, model, *, fields=None, name=None, suffix='', using='',
        db_tablespace=None, col_suffixes=(), sql=None, opclasses=(),
        condition=None, concurrently=False, include=None, expressions=None,
    ):
shimizukawa commented 2 years ago

It has been released https://pypi.org/project/django-redshift-backend/3.0.0/