Don't allow load_status to return None

This commit is contained in:
Justin ! 2023-08-22 23:56:31 -04:00 committed by Hugo
parent 3611e7d62f
commit c073d55b2f
3 changed files with 10 additions and 9 deletions

View file

@ -57,7 +57,7 @@ async def collections_for_pair(
cache_key = _get_collections_cache_key(pair)
if from_cache:
rv = load_status(status_path, pair.name, data_type="collections")
if rv and rv.get("cache_key", None) == cache_key:
if rv.get("cache_key", None) == cache_key:
return list(
_expand_collections_cache(
rv["collections"], pair.config_a, pair.config_b

View file

@ -142,11 +142,11 @@ async def metasync_collection(collection, general, *, connector: aiohttp.TCPConn
try:
cli_logger.info(f"Metasyncing {status_name}")
status = (
load_status(
general["status_path"], pair.name, collection.name, data_type="metadata"
)
or {}
status = load_status(
general["status_path"],
pair.name,
collection.name,
data_type="metadata",
)
a = await storage_instance_from_config(collection.config_a, connector=connector)

View file

@ -6,6 +6,7 @@ import importlib
import json
import os
import sys
from typing import Any
import aiohttp
import click
@ -186,11 +187,11 @@ def load_status(
base_path: str,
pair: str,
collection: str | None = None,
data_type: str | None = None
) -> dict | None:
data_type: str | None = None,
) -> dict[str, Any]:
path = get_status_path(base_path, pair, collection, data_type)
if not os.path.exists(path):
return None
return {}
assert_permissions(path, STATUS_PERMISSIONS)
with open(path) as f: