Bug 2486066 - protobuf3 ships a legacy *-nspkg.pth that breaks under Python 3.15 (KeyError: local variable 'sitedir' is not defined)
Summary: protobuf3 ships a legacy *-nspkg.pth that breaks under Python 3.15 (KeyError:...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: protobuf3
Version: rawhide
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Michel Lind
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2026-06-07 09:40 UTC by Mikhail
Modified: 2026-06-17 12:19 UTC (History)
2 users (show)

Fixed In Version: protobuf3-3.19.6-65.fc45
Clone Of:
Environment:
Last Closed: 2026-06-17 12:19:15 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Mikhail 2026-06-07 09:40:29 UTC
Description of problem:
After the Python 3.15 update in Rawhide every interpreter startup prints a traceback from the legacy google-namespace .pth file shipped in python3-protobuf3:

Error in import line from /usr/lib/python3.15/site-packages/protobuf-3.19.6-py3.15-nspkg.pth: import sys, types, os;p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = __import__('importlib.util');__import__('importlib.machinery');m = sys.modules.setdefault('google', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('google', [os.path.dirname(p)])));m = m or sys.modules.setdefault('google', types.ModuleType('google'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
  Traceback (most recent call last):
    File "<frozen site>", line 533, in _exec_imports
    File "<string>", line 1, in <module>
  KeyError: "local variable ''sitedir'' is not defined"

The line is setuptools' pkg_resources-namespace stub; it gets the site dir via sys._getframe(1).f_locals['sitedir']. Through 3.14 site.addpackage(sitedir, ...) ran the line itself, so frame 1 was addpackage and 'sitedir' was its parameter. 3.15 rewrote site.py (PEP 829, gh-148641/gh-150228) and import lines now run inside StartupState._exec_imports(), which has no 'sitedir', hence the KeyError. The "local variable ... is not defined" text is the PEP 667 fast-locals-proxy KeyError from 3.13.

It's non-fatal, site.py catches it and continues, but it prints at every python3 startup including from scriptlets that run python3. I first saw it in the fedora-third-party triggers, but those complete fine and it isn't specific to them. Import lines in .pth are deprecated by PEP 829 and the stub depends on a private site internal that was never guaranteed, so the fix belongs in the package, not CPython.

Version-Release number of selected component (if applicable):
protobuf3-3.19.6-64.fc45
python3-3.15.0~b2-2.fc45

How reproducible:
Always

Steps to Reproduce:
1. Rawhide with python3-3.15.0~b2 and python3-protobuf3 installed
2. python3 -c ''

Actual results:
A traceback on stderr at every startup (Error in import line ... KeyError ...'sitedir'...).

Expected results:
No output.

Additional info:
Fix: drop the legacy namespace_packages and ship as a PEP 420 native namespace (no *-nspkg.pth generated). Afterwards python3 -c '' is silent and import google.protobuf still works. The google namespace is shared with other packages (google-api-*, grpcio, ...), so check that it still resolves across all co-installed providers after the switch.
Refs: gh-148641, gh-150228 (Barry Warsaw); What's New in Python 3.15, site.StartupState.

Reproducible: Always

Comment 1 Mikhail 2026-06-11 11:50:50 UTC
See example: https://src.fedoraproject.org/rpms/python-paste/pull-request/11

Comment 2 Fedora Update System 2026-06-17 12:15:26 UTC
FEDORA-2026-f49690e24d (protobuf3-3.19.6-65.fc45) has been submitted as an update to Fedora 45.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-f49690e24d

Comment 3 Fedora Update System 2026-06-17 12:19:15 UTC
FEDORA-2026-f49690e24d (protobuf3-3.19.6-65.fc45) has been pushed to the Fedora 45 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.