From 070d7c39b131fb2745981b78a1577bdbb9f5c657 Mon Sep 17 00:00:00 2001 From: Stepan Neretin Date: Tue, 23 Dec 2025 22:01:46 +0700 Subject: [PATCH 1/2] PBCKP-2912: add sanity check in set_archiving(instance should exists) --- pg_probackup2/app.py | 7 +++++++ pg_probackup2/tests/test_basic.py | 25 ++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pg_probackup2/app.py b/pg_probackup2/app.py index eac5d63..4017033 100644 --- a/pg_probackup2/app.py +++ b/pg_probackup2/app.py @@ -778,6 +778,13 @@ def set_archiving( log_level=False, archive_timeout=False, custom_archive_command=None): + # check instance existing + instances_json = self.show(instance=None, as_json=True, expect_error=False, as_text=True) + instances_data = json.loads(instances_json) + if not any(inst_data.get('instance') == instance for inst_data in instances_data): + assert False, "Instance '{0}' does not exist. " \ + "Please add the instance first using add_instance() or init_pb_node().".format(instance) + # parse postgresql.auto.conf options = {} if replica: diff --git a/pg_probackup2/tests/test_basic.py b/pg_probackup2/tests/test_basic.py index 2540ddb..7fe6171 100644 --- a/pg_probackup2/tests/test_basic.py +++ b/pg_probackup2/tests/test_basic.py @@ -5,9 +5,9 @@ import pytest import testgres -from ...pg_probackup2.app import ProbackupApp -from ...pg_probackup2.init_helpers import Init, init_params -from ..storage.fs_backup import FSTestBackupDir +from pg_probackup2.app import ProbackupApp +from pg_probackup2.init_helpers import Init, init_params +from pg_probackup2.storage.fs_backup import FSTestBackupDir class ProbackupTest: @@ -102,3 +102,22 @@ def test_full_backup(self): # Check if the backup is valid assert f"INFO: Backup {backup_id} is valid" in out + + def test_set_archiving_nonexistent_instance(self): + self.pb.init() + + with pytest.raises(AssertionError) as exc_info: + self.pb.set_archiving('nonexistent_instance', None) + + assert "Instance 'nonexistent_instance' does not exist" in str(exc_info.value) + + def test_set_archiving_existing_instance(self): + node = self.pg_node.make_simple('node', pg_options={"fsync": "off", "synchronous_commit": "off"}) + + with node: + self.pb.init() + node.slow_start() + self.pb.add_instance('node', node) + self.pb.set_archiving('node', node) + + assert "does not exist" not in str(self.pb.test_class.output or "") \ No newline at end of file From 99e989c14c3d4880708595dcbdf83a3f99056f6a Mon Sep 17 00:00:00 2001 From: Stepan Neretin Date: Mon, 12 Jan 2026 16:34:56 +0700 Subject: [PATCH 2/2] review fixes --- pg_probackup2/app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pg_probackup2/app.py b/pg_probackup2/app.py index 4017033..8fcd7f9 100644 --- a/pg_probackup2/app.py +++ b/pg_probackup2/app.py @@ -571,7 +571,7 @@ def show( backup_list.append(backup) if backup_id is not None: - assert False, "Failed to find backup with ID: {0}".format(backup_id) + raise RuntimeError("Failed to find backup with ID: {0}".format(backup_id)) return backup_list else: @@ -629,7 +629,7 @@ def show( specific_record[name.strip()] = var if not specific_record: - assert False, "Failed to find backup with ID: {0}".format(backup_id) + raise RuntimeError("Failed to find backup with ID: {0}".format(backup_id)) return specific_record @@ -782,8 +782,8 @@ def set_archiving( instances_json = self.show(instance=None, as_json=True, expect_error=False, as_text=True) instances_data = json.loads(instances_json) if not any(inst_data.get('instance') == instance for inst_data in instances_data): - assert False, "Instance '{0}' does not exist. " \ - "Please add the instance first using add_instance() or init_pb_node().".format(instance) + raise RuntimeError("Instance '{0}' does not exist. " \ + "Please add the instance first using add_instance() or init_pb_node().".format(instance)) # parse postgresql.auto.conf options = {}