KeyError in _OsBackend.stat() for unknown UID/GID in container environments
- Dominant language
- Python
- Stars
- 259
- Forks
- 34
- Avg merge
- 57m
- Merged PRs (30d)
- 1
Description
## 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
```python
# 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.
Contributor guide
Assessment
This issue has not been assessed yet.