Skip to content

Commit 20a46f6

Browse files
legacyremote: accept raise_missing in get/get_many to avoid TypeError with callers that pass it; no behavior change on legacy protocol (fixes #9199)
1 parent f6ac5c4 commit 20a46f6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/borg/legacyremote.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,12 @@ def __len__(self):
664664
def list(self, limit=None, marker=None):
665665
"""actual remoting is done via self.call in the @api decorator"""
666666

667-
def get(self, id, read_data=True):
668-
for resp in self.get_many([id], read_data=read_data):
667+
def get(self, id, read_data=True, raise_missing=True):
668+
for resp in self.get_many([id], read_data=read_data, raise_missing=raise_missing):
669669
return resp
670670

671-
def get_many(self, ids, read_data=True, is_preloaded=False):
671+
def get_many(self, ids, read_data=True, is_preloaded=False, raise_missing=True):
672+
# note: legacy remote protocol does not support raise_missing parameter, so we ignore it here
672673
yield from self.call_many("get", [{"id": id, "read_data": read_data} for id in ids], is_preloaded=is_preloaded)
673674

674675
@api(since=parse_version("1.0.0"))
@@ -747,11 +748,11 @@ def __enter__(self):
747748
def __exit__(self, exc_type, exc_val, exc_tb):
748749
self.close()
749750

750-
def get(self, key, read_data=True):
751-
return next(self.get_many([key], read_data=read_data, cache=False))
751+
def get(self, key, read_data=True, raise_missing=True):
752+
return next(self.get_many([key], read_data=read_data, raise_missing=raise_missing, cache=False))
752753

753-
def get_many(self, keys, read_data=True, cache=True):
754-
for key, data in zip(keys, self.repository.get_many(keys, read_data=read_data)):
754+
def get_many(self, keys, read_data=True, raise_missing=True, cache=True):
755+
for key, data in zip(keys, self.repository.get_many(keys, read_data=read_data, raise_missing=raise_missing)):
755756
yield self.transform(key, data)
756757

757758
def log_instrumentation(self):
@@ -856,10 +857,12 @@ def close(self):
856857
self.cache.clear()
857858
shutil.rmtree(self.basedir)
858859

859-
def get_many(self, keys, read_data=True, cache=True):
860+
def get_many(self, keys, read_data=True, raise_missing=True, cache=True):
860861
# It could use different cache keys depending on read_data and cache full vs. meta-only chunks.
861862
unknown_keys = [key for key in keys if self.prefixed_key(key, complete=read_data) not in self.cache]
862-
repository_iterator = zip(unknown_keys, self.repository.get_many(unknown_keys, read_data=read_data))
863+
repository_iterator = zip(
864+
unknown_keys, self.repository.get_many(unknown_keys, read_data=read_data, raise_missing=raise_missing)
865+
)
863866
for key in keys:
864867
pkey = self.prefixed_key(key, complete=read_data)
865868
if pkey in self.cache:
@@ -877,7 +880,7 @@ def get_many(self, keys, read_data=True, cache=True):
877880
else:
878881
# slow path: eviction during this get_many removed this key from the cache
879882
t0 = time.perf_counter()
880-
data = self.repository.get(key, read_data=read_data)
883+
data = self.repository.get(key, read_data=read_data, raise_missing=raise_missing)
881884
self.slow_lat += time.perf_counter() - t0
882885
transformed = self.add_entry(key, data, cache, complete=read_data)
883886
self.slow_misses += 1

0 commit comments

Comments
 (0)