Skip to content

Commit 5d69e37

Browse files
committed
Fix ReplicationSetup not finding existing destination keys
1 parent 9e8ec9d commit 5d69e37

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

b2sdk/replication/setup.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ def setup_destination(
7979
destination_bucket: Bucket,
8080
) -> Bucket:
8181
api: B2Api = destination_bucket.api
82-
try:
83-
source_configuration = destination_bucket.replication.as_replication_source
84-
except (NameError, AttributeError):
82+
destination_bucket = api.list_buckets(destination_bucket.name)[0] # fresh!
83+
if destination_bucket.replication is None or destination_bucket.replication.as_replication_source is None:
8584
source_configuration = None
86-
try:
87-
destination_configuration = destination_bucket.replication.as_replication_destination
88-
except (NameError, AttributeError):
85+
else:
86+
source_configuration = destination_bucket.replication.as_replication_source
87+
88+
if destination_bucket.replication is None or destination_bucket.replication.as_replication_destination is None:
8989
destination_configuration = ReplicationDestinationConfiguration({})
90+
else:
91+
destination_configuration = destination_bucket.replication.as_replication_destination
9092

9193
keys_to_purge, destination_key = self._get_destination_key(
9294
api,
@@ -134,6 +136,8 @@ def _get_destination_key(
134136
logger.debug('matching destination key found: %s', current_destination_key_id)
135137
key = current_destination_key
136138
# not breaking here since we want to fill the purge list
139+
else:
140+
logger.info('non-matching destination key found: %s', current_destination_key)
137141
if not key:
138142
logger.debug("no matching key found, making a new one")
139143
key = cls._create_destination_key(

0 commit comments

Comments
 (0)