From 26488aa12fea0df459407e0834afbcd30a508542 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Fri, 21 Jul 2023 11:11:24 +0000 Subject: [PATCH] fix(backup):force backup function to return same length ids as when getting snapshots --- selfprivacy_api/backup/backuppers/restic_backupper.py | 6 +++++- tests/test_graphql/test_backup.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/selfprivacy_api/backup/backuppers/restic_backupper.py b/selfprivacy_api/backup/backuppers/restic_backupper.py index b69c85d..e98c4c3 100644 --- a/selfprivacy_api/backup/backuppers/restic_backupper.py +++ b/selfprivacy_api/backup/backuppers/restic_backupper.py @@ -19,6 +19,8 @@ from selfprivacy_api.jobs import Jobs, JobStatus from selfprivacy_api.backup.local_secret import LocalBackupSecret +SHORT_ID_LEN = 8 + class ResticBackupper(AbstractBackupper): def __init__(self, login_flag: str, key_flag: str, storage_type: str) -> None: @@ -177,7 +179,9 @@ class ResticBackupper(AbstractBackupper): @staticmethod def _snapshot_from_fresh_summary(message: dict, repo_name) -> Snapshot: return Snapshot( - id=message["snapshot_id"], + # There is a discrepancy between versions of restic/rclone + # Some report short_id in this field and some full + id=message["snapshot_id"][0:SHORT_ID_LEN], created_at=datetime.datetime.now(datetime.timezone.utc), service_name=repo_name, ) diff --git a/tests/test_graphql/test_backup.py b/tests/test_graphql/test_backup.py index 2fa9531..6d12a5e 100644 --- a/tests/test_graphql/test_backup.py +++ b/tests/test_graphql/test_backup.py @@ -205,6 +205,8 @@ def test_backup_returns_snapshot(backups, dummy_service): snapshot = provider.backupper.start_backup(service_folders, name) assert snapshot.id is not None + assert len(snapshot.id) == len(Backups.get_all_snapshots()[0].id) + assert Backups.get_snapshot_by_id(snapshot.id) is not None assert snapshot.service_name == name assert snapshot.created_at is not None