Skip to content

[HWORKS-3320] Fix import on Python 3.13 when the UID has no passwd entry, release 0.2.4 - #8

Merged
robzor92 merged 4 commits into
0.2.4from
HWORKS-3320-getuser-oserror-0.2.4
Oct 1, 2026
Merged

robzor92 merged 4 commits into
0.2.4from
HWORKS-3320-getuser-oserror-0.2.4

Conversation

@robzor92

@robzor92 robzor92 commented Oct 1, 2026

Copy link
Copy Markdown

https://hopsworks.atlassian.net/browse/HWORKS-3320

On Python 3.13, import aiomysql (and so import hsfs) fails when the process runs as a UID with no /etc/passwd entry and neither USER nor LOGNAME is set, which is the normal case for arbitrary UIDs on OpenShift:

  File ".../aiomysql/connection.py", line 43, in <module>
  File ".../python3.13/getpass.py", line 175, in getuser
    raise OSError('No username set in the environment') from e
OSError: No username set in the environment

Since 3.13, getpass.getuser() raises OSError where it used to raise KeyError, and connection.py catches only KeyError around the import-time DEFAULT_USER = getpass.getuser(). PyMySQL catches both.

Changes

Testing

  • Wheel built from this branch (hopsworks_aiomysql-0.2.4-py3-none-any.whl) and installed into the Python 3.13 python-feature-pipeline image from logicalclocks/docker-images#1078, run as --user 1000670000:0 with USER/LOGNAME unset: import hsfs works and DEFAULT_USER is "unknown". With 0.2.3 the same command fails as above.
  • The upstream regression test passes on Python 3.12.13 and 3.13.14.

Release

This targets 0.2.4, a new release branch cut from 0.2.3 (same commit, 022290e). After merge, run the hopsworks-aiomysql Jenkins job, which builds */0.2.* branches and uploads to PyPI. Then bump hopsworks_aiomysql[sa]==0.2.3 to 0.2.4 in hopsworks-api python/pyproject.toml.

Replaces #7, which targeted master.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KaDhXWqsBJ2QcoePWyrb62

cristianchiriac and others added 4 commits October 1, 2026 08:18
…r entry

Fixes aio-libs#1053. As of Python 3.13, getpass.getuser() raises OSError
instead of KeyError when there's no entry in the OS user database for
the current uid (e.g. an arbitrary uid in a container). The
module-level fallback only caught KeyError, so importing aiomysql
crashed outright in that environment.

Catch OSError too, matching the fix PyMySQL applied for the same
underlying getpass change (referenced in the issue).

(cherry picked from commit 09f2110)
The test's cleanup reloaded aiomysql.connection before monkeypatch
undid the getpass.getuser patch, so the reload still observed the
broken getuser and left DEFAULT_USER stuck at "unknown" afterwards.
The reload also left aiomysql.Connection/aiomysql.connect pointing at
the pre-reload objects while aiomysql.connection.Connection/connect
were replaced, breaking identity checks for any test that runs after
this one.

Undo the monkeypatch before reloading, and reload the parent aiomysql
package too so its re-exported names match the reloaded submodule
again.

(cherry picked from commit 6e8eb18)
https://hopsworks.atlassian.net/browse/HWORKS-3320

The getpass.getuser() OSError fallback needs a release for hopsworks-api
to pin to. Without it, importing aiomysql (and so hsfs) fails on Python
3.13 under a UID with no passwd entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KaDhXWqsBJ2QcoePWyrb62
@robzor92
robzor92 merged commit 116597d into 0.2.4 Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants