Skip to content

Commit a2c0892

Browse files
authored
Merge pull request #2741 from cta-observatory/username_fallback
Catch any exception in _get_username
2 parents 93e86cb + 1b73431 commit a2c0892

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ jobs:
103103
path: ~/.cache/ctapipe
104104
key: ctapipe-test-data-desy
105105

106+
- name: cache astropy data
107+
uses: actions/cache@v4
108+
with:
109+
path: ~/.astropy/cache
110+
key: astropy-cache
111+
106112
- name: Prepare mamba installation
107113
if: matrix.install-method == 'mamba' && contains(github.event.pull_request.labels.*.name, 'documentation-only') == false
108114
env:

docs/changes/2741.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fallback to "Unknown User" in case no username is available
2+
from the system for provenance.

src/ctapipe/io/metadata.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def _get_user_name():
7373
import pwd
7474

7575
return pwd.getpwuid(os.getuid()).pw_gecos
76-
except ImportError:
77-
# the pwd module is not available on some non-unix systems (Windows), so
78-
# here we just fall back to a default name
76+
except Exception:
77+
# the pwd module is not available on some non-unix systems (Windows)
78+
# also, a username might not exist (e.g. in docker containers run with a custom uid)
79+
# so here we just fall back to a default name
7980
return "Unknown User"
8081

8182

0 commit comments

Comments
 (0)