fossasia / eventyay-tickets

https://tickets-dev.eventyay.com
Apache License 2.0
1.51k stars 36 forks source link

Django upgrade 4 #98

Closed eMBee closed 1 month ago

eMBee commented 1 month ago

resubmission of previous commits.

this is a series of PRs that should be reviewed and merged in orderas that is the order in which they were tested:

PR 1: Create dependabot.yml (https://github.com/fossasia/eventyay-tickets/pull/95) PR 2: Add TLS/mTLS settings for postgreSQL and Redis (original: https://github.com/fossasia/eventyay-tickets/pull/47) (#96) PR 3: Removed Python 3.6, 3.7 from GitHub Action script (original https://github.com/fossasia/eventyay-tickets/pull/51) (#97) PR 4: update django to 3.2 (original https://github.com/fossasia/eventyay-tickets/pull/52) (#98)

marcoag commented 1 month ago

1st: can we have a PR with just b5d7f18 to avoid noise? we don't need the other 2 as they are totally independent.

2nd: This changes seem to fail when I try to make migrations with:

  File "/pretix/src/pretix/base/migrations/0102_auto_20181017_0024.py", line 6, in <module>
    from django_mysql.utils import connection_is_mariadb
ImportError: cannot import name 'connection_is_mariadb' from 'django_mysql.utils' (/usr/local/lib/python3.8/site-packages/django_mysql/utils.py)

I don't seem to find a place where the django-mysql package has a pinged version but when I check what version the docker contains I get:

$ pip show django-mysql
Name: django-mysql
Version: 4.13.0

Not sure if we sould ping it to a certain version or drop this connection_is_mariadb somehow... but this function is removed in the python library since 4.5 onward:

https://github.com/adamchainz/django-mysql/commit/40da1f9de6571bf8aef6b99841e7d21bcd53d5b7

mariobehling commented 1 month ago

I assume PRs in "master with changes" that delete MySQL related code should go in here, e.g. https://github.com/fossasia/eventyay-tickets/commit/3c0c683042a352fde138da66698f3eed811f447a

norbusan commented 1 month ago

I gave that branch a run and it looks much better. A few things need to be done:

remove mysql migration

See this change:

diff --git a/src/pretix/base/migrations/0102_auto_20181017_0024.py b/src/pretix/base/migrations/0102_auto_20181017_0024.py
index cbab44764..745a457fe 100644
--- a/src/pretix/base/migrations/0102_auto_20181017_0024.py
+++ b/src/pretix/base/migrations/0102_auto_20181017_0024.py
@@ -2,8 +2,6 @@

 from django.core.exceptions import ImproperlyConfigured
 from django.db import migrations, models
-from django_mysql.checks import mysql_connections
-from django_mysql.utils import connection_is_mariadb

 def set_attendee_name_parts(apps, schema_editor):
@@ -24,40 +22,12 @@ def set_attendee_name_parts(apps, schema_editor):
         ia.save(update_fields=['name_parts'])

-def check_mysqlversion(apps, schema_editor):
-    errors = []
-    any_conn_works = False
-    conns = list(mysql_connections())
-    found = 'Unknown version'
-    for alias, conn in conns:
-        if connection_is_mariadb(conn) and hasattr(conn, 'mysql_version'):
-            if conn.mysql_version >= (10, 2, 7):
-                any_conn_works = True
-            else:
-                found = 'MariaDB ' + '.'.join(str(v) for v in conn.mysql_version)
-        elif hasattr(conn, 'mysql_version'):
-            if conn.mysql_version >= (5, 7):
-                any_conn_works = True
-            else:
-                found = 'MySQL ' + '.'.join(str(v) for v in conn.mysql_version)
-
-    if conns and not any_conn_works:
-        raise ImproperlyConfigured(
-            'As of pretix 2.2, you need MySQL 5.7+ or MariaDB 10.2.7+ to run pretix. However, we detected a '
-            'database connection to {}'.format(found)
-        )
-    return errors
-
-
 class Migration(migrations.Migration):
     dependencies = [
         ('pretixbase', '0101_auto_20181025_2255'),
     ]

     operations = [
-        migrations.RunPython(
-            check_mysqlversion, migrations.RunPython.noop
-        ),
         migrations.RenameField(
             model_name='cartposition',
             old_name='attendee_name',

System check warnings

eventyay-tickets  | System check identified some issues:
eventyay-tickets  | 
eventyay-tickets  | WARNINGS:
eventyay-tickets  | badges.BadgeItem: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
eventyay-tickets  |     HINT: Configure the DEFAULT_AUTO_FIELD setting or the BadgesApp.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
eventyay-tickets  | badges.BadgeLayout: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
eventyay-tickets  |     HINT: Configure the DEFAULT_AUTO_FIELD setting or the BadgesApp.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
eventyay-tickets  | banktransfer.BankImportJob: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
eventyay-tickets  |     HINT: Configure the DEFAULT_AUTO_FIELD setting or the BankTransferApp.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
eventyay-tickets  | banktransfer.BankTransaction: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
eventyay-tickets  |     HINT: Configure the DEFAULT_AUTO_FIELD setting or the BankTransferApp.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
eventyay-tickets  | banktransfer.RefundExport: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
eventyay-tickets  |     HINT: Configure the DEFAULT_AUTO_FIELD setting or the BankTransferApp.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
..... MANY MORE

Runtime errors due to integrity issues

eventyay-tickets  | Running migrations:
eventyay-tickets  | Traceback (most recent call last):
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
eventyay-tickets  |     return self.cursor.execute(sql)
eventyay-tickets  | psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "pg_type_typname_nsp_index"
eventyay-tickets  | DETAIL:  Key (typname, typnamespace)=(django_migrations_id_seq, 2200) already exists.
eventyay-tickets  | 
eventyay-tickets  | 
eventyay-tickets  | The above exception was the direct cause of the following exception:
eventyay-tickets  | 
eventyay-tickets  | Traceback (most recent call last):
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 68, in ensure_schema
eventyay-tickets  |     editor.create_model(self.Migration)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 345, in create_model
eventyay-tickets  |     self.execute(sql, params or None)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 145, in execute
eventyay-tickets  |     cursor.execute(sql, params)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
eventyay-tickets  |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
eventyay-tickets  |     return executor(sql, params, many, context)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
eventyay-tickets  |     return self.cursor.execute(sql, params)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
eventyay-tickets  |     raise dj_exc_value.with_traceback(traceback) from exc_value
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
eventyay-tickets  |     return self.cursor.execute(sql)
eventyay-tickets  | django.db.utils.IntegrityError: duplicate key value violates unique constraint "pg_type_typname_nsp_index"
eventyay-tickets  | DETAIL:  Key (typname, typnamespace)=(django_migrations_id_seq, 2200) already exists.
eventyay-tickets  | 
eventyay-tickets  | 
eventyay-tickets  | During handling of the above exception, another exception occurred:
eventyay-tickets  | 
eventyay-tickets  | Traceback (most recent call last):
eventyay-tickets  |   File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
eventyay-tickets  |     return _run_code(code, main_globals, None,
eventyay-tickets  |   File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
eventyay-tickets  |     exec(code, run_globals)
eventyay-tickets  |   File "/pretix/src/pretix/__main__.py", line 9, in <module>
eventyay-tickets  |     execute_from_command_line(sys.argv)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
eventyay-tickets  |     utility.execute()
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
eventyay-tickets  |     self.fetch_command(subcommand).run_from_argv(self.argv)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
eventyay-tickets  |     self.execute(*args, **cmd_options)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
eventyay-tickets  |     output = self.handle(*args, **options)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
eventyay-tickets  |     res = handle_func(*args, **kwargs)
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 244, in handle
eventyay-tickets  |     post_migrate_state = executor.migrate(
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 91, in migrate
eventyay-tickets  |     self.recorder.ensure_schema()
eventyay-tickets  |   File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 70, in ensure_schema
eventyay-tickets  |     raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
eventyay-tickets  | django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (duplicate key value violates unique constraint "pg_type_typname_nsp_index"
eventyay-tickets  | DETAIL:  Key (typname, typnamespace)=(django_migrations_id_seq, 2200) already exists.
eventyay-tickets  | )

But I could

I did not try creating events etc.

mariobehling commented 1 month ago

Closing this PR in favor of https://github.com/fossasia/eventyay-tickets/pull/102