High severity intermediate · Fix: 5-15 min

CacheMissError

dvc.exceptions.CacheMissError

What this error means
DVC pipeline fails to find cached outputs because one or more dependencies have changed or are missing, causing a cache miss error.

Stack trace

traceback
dvc.exceptions.CacheMissError: Cache miss for dependency 'data/raw/data.csv' in stage 'prepare'
  File "/usr/local/lib/python3.9/site-packages/dvc/stage/__init__.py", line 123, in run
    raise CacheMissError(f"Cache miss for dependency '{dep}' in stage '{self.name}'")
CacheMissError: Cache miss for dependency 'data/raw/data.csv' in stage 'prepare'
QUICK FIX
Run 'dvc repro' to rerun affected pipeline stages and regenerate missing cache entries.

Why it happens

DVC tracks dependencies and outputs via hashes to reuse cached results. If a dependency file is modified, deleted, or missing, DVC cannot find a matching cache entry and raises a CacheMissError. This ensures pipeline correctness by rerunning affected stages.

Detection

Monitor DVC pipeline runs for CacheMissError exceptions and log which dependencies caused cache misses to identify changed or missing files before pipeline failure.

Causes & fixes

1

Dependency file was modified after last pipeline run, changing its hash.

✓ Fix

Revert the dependency file to its original state or accept the change and allow DVC to rerun the pipeline to update the cache.

2

Dependency file was deleted or moved, so DVC cannot find it.

✓ Fix

Restore the missing dependency file to its expected path or update the DVC stage to point to the new location.

3

DVC cache directory was cleared or corrupted, losing cached outputs.

✓ Fix

Restore the DVC cache directory from backup or rerun the pipeline stages to regenerate cache entries.

4

Pipeline stage definition changed dependencies without updating DVC files.

✓ Fix

Run 'dvc repro' to update pipeline stages and cache, or manually update DVC files to reflect new dependencies.

Code: broken vs fixed

Broken - triggers the error
python
import dvc.api

# This will raise CacheMissError if dependency changed or missing
with dvc.api.open('data/raw/data.csv', 'r') as fd:
    data = fd.read()  # Cache miss error triggered here
Fixed - works correctly
python
import os
import dvc.api

os.environ['DVC_CACHE_DIR'] = '/path/to/dvc/cache'  # Ensure cache dir is set

# Wrap in try/except to handle cache miss
try:
    with dvc.api.open('data/raw/data.csv', 'r') as fd:
        data = fd.read()  # Fixed: handle cache miss gracefully
except dvc.exceptions.CacheMissError as e:
    print(f"Cache miss detected: {e}")
    # Optionally trigger pipeline repro here
    import subprocess
    subprocess.run(['dvc', 'repro'])
    with dvc.api.open('data/raw/data.csv', 'r') as fd:
        data = fd.read()

print(data)
Added try/except to catch CacheMissError and rerun the pipeline with 'dvc repro' to regenerate missing cache before retrying the read.

Workaround

Catch CacheMissError, then manually run 'dvc repro' to rebuild missing cache dependencies before continuing pipeline execution.

Prevention

Use DVC's 'dvc status' and 'dvc diff' commands regularly to detect dependency changes early and commit consistent pipeline states to avoid unexpected cache misses.

Python 3.7+ · dvc >=2.0.0 · tested on 2.8.3
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.