EOX GitLab Instance

Skip to content

Storage exists but reported as not existing and existing (?)

During registration it is possible that same storage with slightly different parameters cannot be recognized. In my case the storage was initially created by timeseries (zarr) registration, then I tried to register regular products and ran into the following. Storage.get_or_create attempts to retrieve probably, fails, and tries to create with same name already existing.

2022-12-07T21:05:11.623232549Z Traceback (most recent call last):
2022-12-07T21:05:11.623235739Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 581, in get_or_create
2022-12-07T21:05:11.623238779Z     return self.get(**kwargs), False
2022-12-07T21:05:11.623241359Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 435, in get
2022-12-07T21:05:11.623244069Z     raise self.model.DoesNotExist(
2022-12-07T21:05:11.623246449Z eoxserver.backends.models.Storage.DoesNotExist: Storage matching query does not exist.
2022-12-07T21:05:11.623248959Z
2022-12-07T21:05:11.623251389Z During handling of the above exception, another exception occurred:
2022-12-07T21:05:11.623253959Z
2022-12-07T21:05:11.623256309Z Traceback (most recent call last):
2022-12-07T21:05:11.623258739Z   File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
2022-12-07T21:05:11.623261309Z     return self.cursor.execute(sql, params)
2022-12-07T21:05:11.623263719Z psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "backends_storage_name_key"
2022-12-07T21:05:11.623266329Z DETAIL:  Key (name)=(eox-fusion) already exists.
2022-12-07T21:05:11.623268729Z
2022-12-07T21:05:11.623270989Z
2022-12-07T21:05:11.623273289Z The above exception was the direct cause of the following exception:
2022-12-07T21:05:11.623275739Z
2022-12-07T21:05:11.623278009Z Traceback (most recent call last):
2022-12-07T21:05:11.623280399Z   File "/usr/local/lib/python3.10/dist-packages/registrar-3.2.5a14-py3.10.egg/registrar/daemon.py", line 53, in run_daemon
2022-12-07T21:05:11.623283129Z     register(route_cfg, config.sources, value)
2022-12-07T21:05:11.623287189Z   File "/usr/local/lib/python3.10/dist-packages/registrar-3.2.5a14-py3.10.egg/registrar/registrar.py", line 53, in register
2022-12-07T21:05:11.623289849Z     backend.register(source, item, replace=False)
2022-12-07T21:05:11.623292329Z   File "/usr/lib/python3.10/contextlib.py", line 79, in inner
2022-12-07T21:05:11.623294999Z     return func(*args, **kwds)
2022-12-07T21:05:11.623297399Z   File "/usr/local/lib/python3.10/dist-packages/registrar-3.2.5a14-py3.10.egg/registrar/backend/eoxserver.py", line 352, in register
2022-12-07T21:05:11.623305859Z     storage = self._get_storage_from_source(source, item)
2022-12-07T21:05:11.623308389Z   File "/usr/local/lib/python3.10/dist-packages/registrar-3.2.5a14-py3.10.egg/registrar/backend/eoxserver.py", line 169, in _get_storage_from_source
2022-12-07T21:05:11.623311069Z     storage, created_storage = backends.Storage.objects.get_or_create(
2022-12-07T21:05:11.623314240Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method
2022-12-07T21:05:11.623316940Z     return getattr(self.get_queryset(), name)(*args, **kwargs)
2022-12-07T21:05:11.623319400Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 588, in get_or_create
2022-12-07T21:05:11.623322070Z     return self.create(**params), True
2022-12-07T21:05:11.623324500Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 453, in create
2022-12-07T21:05:11.623327110Z     obj.save(force_insert=True, using=self.db)
2022-12-07T21:05:11.623329520Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 739, in save
2022-12-07T21:05:11.623332100Z     self.save_base(using=using, force_insert=force_insert,
2022-12-07T21:05:11.623334550Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 776, in save_base
2022-12-07T21:05:11.623337110Z     updated = self._save_table(
2022-12-07T21:05:11.623339470Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 881, in _save_table
2022-12-07T21:05:11.623342060Z     results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
2022-12-07T21:05:11.623344510Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/base.py", line 919, in _do_insert
2022-12-07T21:05:11.623347080Z     return manager._insert(
2022-12-07T21:05:11.623349420Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/manager.py", line 85, in manager_method
2022-12-07T21:05:11.623352020Z     return getattr(self.get_queryset(), name)(*args, **kwargs)
2022-12-07T21:05:11.623354430Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/query.py", line 1270, in _insert
2022-12-07T21:05:11.623356990Z     return query.get_compiler(using=using).execute_sql(returning_fields)
2022-12-07T21:05:11.623359430Z   File "/usr/local/lib/python3.10/dist-packages/django/db/models/sql/compiler.py", line 1416, in execute_sql
2022-12-07T21:05:11.623362020Z     cursor.execute(sql, params)
2022-12-07T21:05:11.623364370Z   File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 98, in execute
2022-12-07T21:05:11.623366940Z     return super().execute(sql, params)
2022-12-07T21:05:11.623369330Z   File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 66, in execute
2022-12-07T21:05:11.623371880Z     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
2022-12-07T21:05:11.623374340Z   File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
2022-12-07T21:05:11.623378760Z     return executor(sql, params, many, context)
2022-12-07T21:05:11.623381190Z   File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 79, in _execute
2022-12-07T21:05:11.623384070Z     with self.db.wrap_database_errors:
2022-12-07T21:05:11.623386480Z   File "/usr/local/lib/python3.10/dist-packages/django/db/utils.py", line 90, in __exit__
2022-12-07T21:05:11.623389050Z     raise dj_exc_value.with_traceback(traceback) from exc_value
2022-12-07T21:05:11.623391480Z   File "/usr/local/lib/python3.10/dist-packages/django/db/backends/utils.py", line 84, in _execute
2022-12-07T21:05:11.623394060Z     return self.cursor.execute(sql, params)
2022-12-07T21:05:11.623396451Z django.db.utils.IntegrityError: duplicate key value violates unique constraint "backends_storage_name_key"
2022-12-07T21:05:11.623399071Z DETAIL:  Key (name)=(eox-fusion) already exists.

A workaround currently is to rename existing storage.

Edited by Nikola Jankovic