# Buggy code
def get(self, path_info):
    """Gets the checksum for the specified path info. Checksum will be
    retrieved from the state database if available.

    Args:
        path_info (dict): path info to get the checksum for.

    Returns:
        str or None: checksum for the specified path info or None if it
        doesn't exist in the state database.
    """
    assert isinstance(path_info, str) or path_info.scheme == "local"
    path = os.fspath(path_info)

    if not os.path.exists(path):
        return None

    actual_mtime, actual_size = get_mtime_and_size(path, self.repo.tree)
    actual_inode = get_inode(path)

    existing_record = self.get_state_record_for_inode(actual_inode)
    if not existing_record:
        return None

    mtime, size, checksum, _ = existing_record
    if self._file_metadata_changed(actual_mtime, mtime, actual_size, size):
        return None

    self._update_state_record_timestamp_for_inode(actual_inode)
    return checksum


# Traceback (AssertionError)
$ dvc fetch -aT -v
2020-05-22 23:02:45,092 DEBUG: PRAGMA user_version;
2020-05-22 23:02:45,092 DEBUG: fetched: [(3,)]
2020-05-22 23:02:45,092 DEBUG: CREATE TABLE IF NOT EXISTS state (inode INTEGER PRIMARY KEY, mtime TEXT NOT NULL, size TEXT NOT NULL, md5 TEXT NOT NULL, timestamp TEXT NOT NULL)
2020-05-22 23:02:45,093 DEBUG: CREATE TABLE IF NOT EXISTS state_info (count INTEGER)
2020-05-22 23:02:45,093 DEBUG: CREATE TABLE IF NOT EXISTS link_state (path TEXT PRIMARY KEY, inode INTEGER NOT NULL, mtime TEXT NOT NULL)
2020-05-22 23:02:45,093 DEBUG: INSERT OR IGNORE INTO state_info (count) SELECT 0 WHERE NOT EXISTS (SELECT * FROM state_info)
2020-05-22 23:02:45,093 DEBUG: PRAGMA user_version = 3;
2020-05-22 23:02:45,117 DEBUG: Assuming '/home/hardik/src/example-get-started/.dvc/cache/42/c7025fc0edeb174069280d17add2d4.dir' is unchanged since it is read-only
2020-05-22 23:02:45,117 DEBUG: Assuming '/home/hardik/src/example-get-started/.dvc/cache/42/c7025fc0edeb174069280d17add2d4.dir' is unchanged since it is read-only
2020-05-22 23:02:45,117 DEBUG: Assuming '/home/hardik/src/example-get-started/.dvc/cache/68/36f797f3924fb46fcfd6b9f6aa6416.dir' is unchanged since it is read-only
2020-05-22 23:02:45,118 DEBUG: Assuming '/home/hardik/src/example-get-started/.dvc/cache/68/36f797f3924fb46fcfd6b9f6aa6416.dir' is unchanged since it is read-only
2020-05-22 23:02:45,184 DEBUG: SELECT count from state_info WHERE rowid=?
2020-05-22 23:02:45,184 DEBUG: fetched: [(7,)]
2020-05-22 23:02:45,184 DEBUG: UPDATE state_info SET count = ? WHERE rowid = ?
2020-05-22 23:02:45,197 ERROR: unexpected error
------------------------------------------------------------
Traceback (most recent call last):
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/main.py", line 49, in main
ret = cmd.run()
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/command/data_sync.py", line 75, in run
recursive=self.args.recursive,
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/repo/__init__.py", line 30, in wrapper
ret = f(repo, *args, **kwargs)
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/repo/__init__.py", line 536, in fetch
return self._fetch(*args, **kwargs)
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/repo/fetch.py", line 45, in _fetch
recursive=recursive,
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/repo/__init__.py", line 295, in used_cache
filter_info=filter_info,
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/stage/__init__.py", line 761, in get_used_cache
cache.update(out.get_used_cache(*args, **kwargs))
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/output/base.py", line 449, in get_used_cache
self.checksum, self._collect_used_dir_cache(**kwargs),
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/output/base.py", line 363, in _collect_used_dir_cache
if self.cache.changed_cache_file(self.checksum):
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/remote/base.py", line 805, in changed_cache_file
if self.is_protected(cache_info):
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/remote/local.py", line 719, in is_protected
if not self.exists(path_info):
File "/home/hardik/miniconda3/lib/python3.7/site-packages/dvc/remote/local.py", line 97, in exists
assert is_working_tree(self.repo.tree)
AssertionError
------------------------------------------------------------

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!

# Fixed code
def get(self, path_info):
    """Gets the checksum for the specified path info. Checksum will be
    retrieved from the state database if available.

    Args:
        path_info (dict): path info to get the checksum for.

    Returns:
        str or None: checksum for the specified path info or None if it
        doesn't exist in the state database.
    """
    assert isinstance(path_info, str) or path_info.scheme == "local"
    path = os.fspath(path_info)

    if not os.path.exists(path):
        return None

    actual_mtime, actual_size = get_mtime_and_size(path, self.tree)
    actual_inode = get_inode(path)

    existing_record = self.get_state_record_for_inode(actual_inode)
    if not existing_record:
        return None

    mtime, size, checksum, _ = existing_record
    if self._file_metadata_changed(actual_mtime, mtime, actual_size, size):
        return None

    self._update_state_record_timestamp_for_inode(actual_inode)
    return checksum