apache/beam · error · AssertionError
Failed to generate a unique UUID for schema after 100…
Error message
Failed to generate a unique UUID for schema after 100 tries! Registry contains {len(self.by_id)} schemas. What it means
The schema registry assigns each schema a UUID by retrying uuid4() up to 100 times until it finds one not already in by_id. If after 100 tries none were unique, it raises this AssertionError. In practice this means either a corrupted/poisoned registry (non-random uuid4, monkeypatched uuid) or an astronomically unlikely collision — with real uuid4 this is effectively an internal invariant violation.
Solutions
- Stop stubbing/mocking uuid.uuid4 to return a fixed value in this process
- Inspect the registry (len(by_id)) for duplicate/poisoned ids and clear it: SCHEMA_REGISTRY entries shouldn't collide for distinct schemas
- Upgrade Beam; retrying 100 uuid4 draws failing is virtually impossible with a healthy RNG
Example fix
// before
mock.patch('uuid.uuid4', return_value='fixed-id') # 100 iterations all collide
// after
mock.patch('uuid.uuid4', side_effect=[str(uuid4()) for _ in range(100)]) Defensive patterns
Strategy: try-catch
Validate before calling
if any(sid == str(uuid4()) for sid in registry.by_id): # sanity check only ...
Try / catch
try: schema_id = registry.generate_new_id() except AssertionError as e: registry.clear(); schema_id = registry.generate_new_id()
Prevention
- Never monkeypatch uuid.uuid4 to a constant in tests
- Reset the schema registry between test cases if you stub RNGs
When it happens
Trigger: Calling `generate_new_id()` (indirectly via `SchemaRegistry.add` / creating a schema-aware type) while the registry's by_id dict is corrupted or uuid4 is patched to return a constant value present in the registry.
Common situations: Test suites monkeypatching uuid.uuid4 with deterministic stubs; custom UUID generators reused for many schemas; extremely large registries with a broken RNG.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Failed assert: element
- Failed assert: [] == %r
- Failed assert: %r == %r
- Failed assert: Received element
- Failed assert: unmatched elements
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/f2cc5131afbc4e6c.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/typehints/schema_registry.py:37
any backwards-compatibility guarantee.
"""
from uuid import uuid4
# Registry of typings for a schema by UUID
class SchemaTypeRegistry(object):
def __init__(self):
self.by_id = {}
self.by_typing = {} # currently not used
def generate_new_id(self):
for _ in range(100):
schema_id = str(uuid4())
if schema_id not in self.by_id:
return schema_id
raise AssertionError(
"Failed to generate a unique UUID for schema after "
f"100 tries! Registry contains {len(self.by_id)} "
"schemas.")
def add(self, typing, schema):
if schema.id:
self.by_id[schema.id] = (typing, schema)
def load_registered_typings(self, by_id):
for id, typing in by_id.items():
if id not in self.by_id:
self.by_id[id] = (typing, None)
def get_registered_typings(self):
# Used by save_main_session, as pb2.schema isn't picklable
return {k: v[0] for k, v in self.by_id.items()}
def get_typing_by_id(self, unique_id):View on GitHub (pinned to 12126d8942)