DHRI-Curriculum / django-app

2 stars 3 forks source link

Ingest problem: slugs are not handled correctly #492

Closed kallewesterling closed 3 years ago

kallewesterling commented 3 years ago

Currently an error occurs when you try to run the python manage.py ingest command when the database already has the requested Workshop. (I believe the problem happens with all the objects that may have slugs. This is high priority.

Traceback (most recent call last):
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: UNIQUE constraint failed: workshop_workshop.slug

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/Users/kallewesterling/Repositories/DHRI-Curriculum/django-app/backend/management/commands/ingest.py", line 80, in handle
    call_command('ingestworkshop',
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/core/management/__init__.py", line 168, in call_command
    return command.execute(*args, **defaults)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/Users/kallewesterling/Repositories/DHRI-Curriculum/django-app/backend/management/commands/ingestworkshop.py", line 117, in handle
    workshop.save_slug()
  File "/Users/kallewesterling/Repositories/DHRI-Curriculum/django-app/workshop/models.py", line 38, in save_slug
    super(Workshop, self).save()
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/base.py", line 745, in save
    self.save_base(using=using, force_insert=force_insert,
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/base.py", line 782, in save_base
    updated = self._save_table(
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/base.py", line 864, in _save_table
    updated = self._do_update(base_qs, using, pk_val, values, update_fields,
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/base.py", line 917, in _do_update
    return filtered._update(values) > 0
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/query.py", line 771, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1500, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1152, in execute_sql
    cursor.execute(sql, params)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/kallewesterling/opt/anaconda3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: workshop_workshop.slug
kallewesterling commented 3 years ago

See save_slug function