Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to delete a profile #6531

Open
unkcpz opened this issue Jul 17, 2024 · 2 comments
Open

Failed to delete a profile #6531

unkcpz opened this issue Jul 17, 2024 · 2 comments

Comments

@unkcpz
Copy link
Member

unkcpz commented Jul 17, 2024

  • aiida-core==2.6.1

I got following error when I try to delete a profile, not sure what happened. Seems it ask me for the password to DB but I got no chance to input the password.

❯ verdi profile delete 2024-07-daint
Warning: Do you also want to permanently delete all data? [y/N]: y
Warning: Deleting profile `2024-07-daint`, including all data.
Warning: This operation cannot be undone, are you sure you want to continue? [y/N]: y
sudo: a password is required

Unable to autodetect postgres setup.
Report: Deleted repository at `/home/jyu/project/sssp-project/.aiida/repository/2024-07-daint`.
Traceback (most recent call last):
  File "/home/jyu/.aiida_venvs/sssp-project/bin/verdi", line 8, in <module>
    sys.exit(verdi())
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/cmdline/groups/verdi.py", line 117, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/cmdline/commands/cmd_profile.py", line 268, in profile_delete
    get_config().delete_profile(profile.name, delete_storage=delete_data)
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/manage/configuration/config.py", line 584, in delete_profile
    storage.delete()
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/storage/psql_dos/backend.py", line 372, in delete
    if postgres.db_exists(config['database_name']):
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/manage/external/postgres.py", line 162, in db_exists
    return bool(self.execute(_CHECK_DB_EXISTS_COMMAND.format(dbname)))
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/pgsu/__init__.py", line 122, in execute
    raise ConnectionError(
ConnectionError: Could not connect to PostgreSQL server using dsn={dsn}.
Consider providing connection parameters via PGSU(dsn={...}).

When I run again, it failed with:

❯ verdi profile delete 2024-07-daint
Warning: Do you also want to permanently delete all data? [y/N]: y
Warning: Deleting profile `2024-07-daint`, including all data.
Warning: This operation cannot be undone, are you sure you want to continue? [y/N]: y
Traceback (most recent call last):
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/storage/psql_dos/migrator.py", line 198, in get_repository_uuid
    return self.get_container().container_id
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/disk_objectstore/container.py", line 434, in container_id
    return self._get_repository_config()["container_id"]  # type: ignore[return-value]
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/disk_objectstore/container.py", line 393, in _get_repository_config
    raise NotInitialised(
disk_objectstore.exceptions.NotInitialised: The container is not initialised yet - use .init_container() first

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

Traceback (most recent call last):
  File "/home/jyu/.aiida_venvs/sssp-project/bin/verdi", line 8, in <module>
    sys.exit(verdi())
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/cmdline/groups/verdi.py", line 117, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jyu/.aiida_venvs/sssp-project/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/cmdline/commands/cmd_profile.py", line 268, in profile_delete
    get_config().delete_profile(profile.name, delete_storage=delete_data)
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/manage/configuration/config.py", line 583, in delete_profile
    storage = storage_cls(profile)
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/storage/psql_dos/backend.py", line 140, in __init__
    migrator.validate_storage()
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/storage/psql_dos/migrator.py", line 168, in validate_storage
    repository_uuid = self.get_repository_uuid()
  File "/home/jyu/project/sssp-project/aiida-core/src/aiida/storage/psql_dos/migrator.py", line 200, in get_repository_uuid
    raise exceptions.UnreachableStorage(
aiida.common.exceptions.UnreachableStorage: Could not access disk-objectstore <disk_objectstore.container.Container object at 0x7fb488932290>: The container is not initialised yet - use .init_container() first

Seems DOS is deleted already but not DB so get into a break edge condition.

@unkcpz
Copy link
Member Author

unkcpz commented Jul 18, 2024

Hi @sphuber, I try to implement a flag to allow disable the storage validation check in "File "/home/jyu/project/sssp-project/aiida-core/src/aiida/storage/psql_dos/backend.py", line 140" where the issue raised. But then I need to change all __init__ method of backends, which is not idea I assume.
Can you give a suggestion which is best way to fix it? I comment out the validate_storage and it back to the first error I have ask me to input password but not actually wait me to do so.

@sphuber
Copy link
Contributor

sphuber commented Jul 19, 2024

Yeah that is a tricky one. The design intentionally only allows a StorageBackend implementation to be instantiated if the storage is valid. I am not sure if we should start building in exceptions or workarounds to this principle.

I think we should leave that problem for now and simply change the deletion order of object-store and PSQL database. The former is very unlikely to fail compared to the latter. So if the former succeeds, we can be relatively sure that the object store deletion will also work (since it is just deleting a folder) and so the profile storage deletion should be "pseudo-atomic".

So I would for now just change that order and manually restore the container in your storage so the validation passes. You can then try to figure out why the PSQL connection fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants