archesproject / arches

Arches is a web platform for creating, managing, & visualizing geospatial data. Arches was inspired by the needs of the Cultural Heritage community, particularly the widespread need of organizations to build & manage cultural heritage inventories
GNU Affero General Public License v3.0
211 stars 142 forks source link

Use db_default for auto-UUID fields in Django 5 #10958

Open jacobtylerwalls opened 3 months ago

jacobtylerwalls commented 3 months ago

When Django 5 is the minimum required version, we can just use db_default for database-generated UUIDs and drop our custom implementation, which currently throws errors if you try to manage.py sqlmigrate:

$ manage.py sqlmigrate models 0001
Traceback (most recent call last):
  File "/Users/jwalls/prj/arches/manage.py", line 27, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/jwalls/django/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/jwalls/django/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/jwalls/django/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/jwalls/django/django/core/management/commands/sqlmigrate.py", line 38, in execute
    return super().execute(*args, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/core/management/commands/sqlmigrate.py", line 80, in handle
    sql_statements = loader.collect_sql(plan)
                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/db/migrations/loader.py", line 381, in collect_sql
    state = migration.apply(state, schema_editor, collect_sql=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/db/migrations/migration.py", line 108, in apply
    schema_editor.collected_sql.append("-- %s" % operation.describe())
                                                 ^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/prj/arches/arches/db/migration_operations/extras.py", line 126, in describe
    return "Sets default value for uuid column(s) %s in %s" % self.columns, self.table
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
TypeError: not enough arguments for format string
jacobtylerwalls commented 2 months ago

Consider removing CreateAutoPopulateUUIDField at the same time.