Skip to content

KeyError in _OsBackend.stat() for unknown UID/GID in container environments #790

Description

@bzantium

Bug

_OsBackend.stat() in etils/epath/backend.py crashes with KeyError when a file is owned by a UID/GID not present in /etc/passwd or /etc/group.

This is common in:

  • Container environments where the host UID doesn't exist inside the container
  • Shared/network filesystems (NFS, FUSE) where files are owned by remote UIDs

Reproduction

# In a container where files are owned by UID 1000 but /etc/passwd has no entry for it:
from etils import epath
p = epath.Path("/some/file/owned/by/unknown/uid")
p.stat()  # KeyError: 'getpwuid(): uid not found: 1000'

Traceback

File "etils/epath/gpath.py", line 293, in stat
    return self._backend.stat(self._path_str)
File "etils/epath/backend.py", line 235, in stat
    owner = pwd.getpwuid(st.st_uid).pw_name
KeyError: 'getpwuid(): uid not found: 1000'

Impact

Downstream libraries like orbax-checkpoint call epath.Path.stat() during checkpoint loading, causing crashes that are difficult to work around.

Suggested fix

Catch KeyError and fall back to the numeric UID/GID as a string, consistent with how ls -n handles unknown UIDs.

See PR #789.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions