GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Pickling ClientError or ServerError returns a plain APIError · Issue #3430 · googleapis/python-genai

Pickling ClientError or ServerError returns a plain APIError #3430

New issue
Copy link
New issue
Copy link
Todo
Todo
Pickling ClientError or ServerError returns a plain APIError#3430
Copy link
Assignees
Venkaiahbabuneelam
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@chaitanya0305
chaitanya0305
opened on Nov 27, 2026
Issue body actions

Environment details

  • Programming language: Python
  • OS: macOS (not OS specific)
  • Language runtime version: 3.12
  • Package version: google-genai 3.6.1, main at 36e2970

Description

After a pickle round trip, errors.ClientError and errors.ServerError come back as plain errors.APIError. Code, message and status are kept, but the class is lost.

Exceptions are pickled whenever an error crosses a process boundary: concurrent.futures.ProcessPoolExecutor, multiprocessing.Pool, Ray, Celery and similar. In those setups except errors.ClientError: (or except errors.ServerError:) in the parent process no longer matches, so 4xx/5xx handling and retry logic based on the error class is silently skipped.

#1144 made APIError picklable (PR #1802), but the fix always rebuilds an APIError.

Steps to reproduce

Runs offline. No API call is made.

import pickle
from concurrent.futures import ProcessPoolExecutor

from google.genai import errors


def call_api():
  # Stands in for a client call that gets a 404 from the API.
  raise errors.ClientError(
      404, {'error': {'code': 404, 'message': 'Not found', 'status': 'NOT_FOUND'}}
  )


if __name__ == '__main__':
  e = errors.ClientError(404, {'error': {'code': 404, 'status': 'NOT_FOUND'}})
  print('after pickle:', type(pickle.loads(pickle.dumps(e))).__name__)

  with ProcessPoolExecutor(max_workers=1) as pool:
    try:
      pool.submit(call_api).result()
    except errors.ClientError:
      print('caught ClientError')
    except errors.APIError as err:
      print('missed ClientError, got', type(err).__name__)

Expected:

after pickle: ClientError
caught ClientError

Actual:

after pickle: APIError
missed ClientError, got APIError

Root cause

google/genai/errors.py:100-105:

return (self.__class__._rebuild, (state,))

@staticmethod
def _rebuild(state: dict[str, Any]) -> 'APIError':
  obj = APIError.__new__(APIError)

_rebuild hard-codes APIError, so the subclass is dropped.

Suggested fix: pass self.__class__ to _rebuild and create the object with it. Keep the class argument optional so errors pickled by older versions still load.

A tested fix with a regression test is ready on branch chaitanya0305:fix/api-error-pickle-subclass.

Activity

  1. Venkaiahbabuneelam
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Nov 28, 2026
  2. Venkaiahbabuneelam
    self-assigned this
    on Nov 28, 2026
  3. Venkaiahbabuneelam
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Nov 28, 2026
  4. Venkaiahbabuneelam commented on Nov 28, 2026

    @Venkaiahbabuneelam
    Venkaiahbabuneelam
    on Nov 28, 2026
    More actions

    Hi @chaitanya0305, we have successfully reproduced this issue:,ClientError ↗ and ServerError ↗ unpickle as plain APIError ↗ because APIError.reduce() ↗ omits self.class and APIError._rebuild() ↗ hardcodes APIError.new(APIError). We verified that passing self.class to APIError._rebuild(state, cls=None) ↗ fixes the issue while preserving backward compatibility. we will file a bug internally.

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Venkaiahbabuneelam
    Venkaiahbabuneelam

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.