Skip to content

google-cloud-compute fails to import on Python 3.14 — protobuf<5 pins incompatible protobuf 4.x (TypeError: Metaclasses with custom tp_new are not supported) #18127

Description

@liucy1983

Determine this is the right repository

  • I determined this is the correct repository in which to report this bug.

Summary of the issue

Context
I upgraded our project to Python 3.14 (CPython 3.14.7, via mise/uv). google-cloud-compute is a direct dependency (currently ==1.15.0). Its metadata declares protobuf>=3.19.5,<5.0.0dev, so the resolver installs the newest allowed protobuf on the 4.x line.

Expected Behavior:
import google.cloud.compute works on Python 3.14, the same way it works on 3.11–3.13.

Actual Behavior:
Importing the package (or any package that pulls in protobuf, e.g. temporalio) immediately raises TypeError: Metaclasses with custom tp_new are not supported. on Python 3.14. protobuf 4.x ships a C extension whose metaclass uses a custom tp_new, which CPython 3.14 now rejects. The protobuf<5 upper bound blocks the only line (protobuf 6.x) whose C extension is fixed for 3.14.

API client name and version

google-cloud-compute==1.15.0

Reproduction steps: code

file: main.py

import google.cloud.compute  # raises TypeError on Python 3.14
print("ok")

### Reproduction steps: supporting files

No extra data files are required. The only relevant constraint is the version pin resolved from the dependency:

file: requirements.txt (minimal)

google-cloud-compute==1.15.0


### Reproduction steps: actual results

$ python3 -c "import google.cloud.compute"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../site-packages/google/cloud/compute/__init__.py", line 18, in <module>
    ...
  File ".../site-packages/google/protobuf/internal/api_implementation.py", line 51, in <module>
    if _CanImport('google._upb._message'):
  File ".../site-packages/google/protobuf/internal/api_implementation.py", line 41, in _CanImport
    mod = importlib.import_module(mod_name)
  File ".../lib/python3.14/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name, level)
TypeError: Metaclasses with custom tp_new are not supported.

Setting PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python does NOT help: protobuf probes
google._upb._message first and the probe itself raises TypeError (not ImportError), so the
pure-Python fallback never engages.

### Reproduction steps: expected results

$ python3 -c "import google.cloud.compute"
ok

### OS & version + platform

macOS 27 (Golden Gate), Apple Silicon (arm64) 

### Python environment

Python 3.14.7

### Python dependencies

pip list | grep -iE "protobuf|google-cloud-compute|google-api-core|proto-plus"
google-api-core          2.27.0
google-cloud-compute    1.15.0
proto-plus              1.26.1
protobuf                4.25.9   # forced by google-cloud-compute <5.0.0dev

### Additional context

Root cause
  google-cloud-compute pins `protobuf>=3.19.5,<5.0.0dev`. On Python 3.14:
  - protobuf 4.25.9 (highest allowed) -> C extension fails with
    `TypeError: Metaclasses with custom tp_new are not supported.`
    (CPython 3.14 forbids custom-tp_new metaclasses).
  - protobuf 6.x (C extension fixed for 3.14) -> blocked by the <5 upper bound.
  This is a hard deadlock for anyone running google-cloud-compute on Python 3.14.

Evidence that 6.x works at runtime
  We forced protobuf 6.33.6 (uv `override-dependencies = ["protobuf>=6.31.0,<7"]`)
  and verified on Python 3.14.7:
  - import google.cloud.compute -> OK
  - import temporalio (also protobuf-dependent) -> OK
  - protobuf message serialization round-trips -> OK
  - temporalio generated *_pb2 round-trips -> OK
  So the <5 upper bound is overly conservative; the client runs fine on protobuf 6.x.

Suggested fix
  Loosen the protobuf upper bound in google-cloud-compute, e.g. to <8.0.0
  (consistent with the other google-cloud-* clients) or at least <7.0.0, and add a
  Python 3.14 CI job so this regression is caught earlier.

Workaround (for affected users)
  - With uv: override-dependencies = ["protobuf>=6.31.0,<7"] in [tool.uv].
  - With pip: pip install --no-deps "google-cloud-compute==1.15.0" "protobuf>=6.31.0"
    then resolve the rest normally.

Related: temporalio already allows protobuf>=3.20,<8.0.0, confirming 6.x is the intended target line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions