INNER CODE UNIT · Python

_check_storage_consistency

shenmintao/marginalia · src/marginalia/main.py:152

async def _check_storage_consistency(settings) -> None:
    """Detect when STORAGE_BACKEND was switched without migrating
    existing files. UUID-shaped storage_keys imply local; relative
    paths with slashes imply mirror — mixing them silently breaks.

    Raises StorageBackendMismatchError on conflict; the error message
    points the user at `marginalia storage migrate`.
    """
    from marginalia.db.engine import get_session_factory
    from marginalia.repositories import files as files_repo

    factory = get_session_factory()
    async with factory() as s:
        sample = await files_repo.sample_live_storage_keys(s, limit=5)
    if not sample:
        return  # empty db, nothing to check

    def _looks_uuid_flat(k: str) -> bool:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…