I think this bug occurs when an artist changes their name. So when the program tries to create/find the artist, it can't find an exact copy of the existing one (due to the new name) and tries to create a new one with the same artist key and thus crashing.
Relevant stack trace:
Traceback (most recent call last):
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 538, in get_or_create
return self.get(**kwargs), False
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 408, in get
self.model._meta.object_name
api.models.DoesNotExist: Artist matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "api_artist_pkey"
DETAIL: Key (id)=(0xOeVMOz2fVg5BJY3N6akT) already exists.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/kevin/coding/spotify-lib-vis/src/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/kevin/coding/spotify-lib-vis/src/api/management/commands/update-history.py", line 10, in handle
parse_history(User.objects.get(id=user_id).secret)
File "/home/kevin/coding/spotify-lib-vis/src/api/utils.py", line 372, in parse_history
user_headers)
File "/home/kevin/coding/spotify-lib-vis/src/api/utils.py", line 252, in save_track_artists
name=artist_dict['name'],)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 541, in get_or_create
return self._create_object_from_params(kwargs, params)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 583, in _create_object_from_params
raise e
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 575, in _create_object_from_params
obj = self.create(**params)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 422, in create
obj.save(force_insert=True, using=self.db)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/base.py", line 741, in save
force_update=force_update, update_fields=update_fields)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/base.py", line 779, in save_base
force_update, using, update_fields,
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/base.py", line 908, in _do_insert
using=using, raw=raw)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1332, in execute_sql
cursor.execute(sql, params)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/kevin/coding/spotify-lib-vis/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "api_artist_pkey"
DETAIL: Key (id)=(0xOeVMOz2fVg5BJY3N6akT) already exists.
I think this bug occurs when an artist changes their name. So when the program tries to create/find the artist, it can't find an exact copy of the existing one (due to the new name) and tries to create a new one with the same artist key and thus crashing.
Relevant stack trace: