Skip to content

Make @doc annotation Serializable for Beam DoFn compatibility#5881

Open
spkrka wants to merge 3 commits intospotify:mainfrom
spkrka:fix-doc-annotation-serializable
Open

Make @doc annotation Serializable for Beam DoFn compatibility#5881
spkrka wants to merge 3 commits intospotify:mainfrom
spkrka:fix-doc-annotation-serializable

Conversation

@spkrka
Copy link
Member

@spkrka spkrka commented Feb 5, 2026

The @doc annotation is used to add documentation metadata to Avro schemas
generated via AvroType.toSchema. However, when AvroType instances are
captured in Beam DoFn closures (e.g., when converting case classes to
GenericRecord inside a transform), the @doc annotation must be serializable.

This change adds 'with Serializable' to the doc annotation class, making
it compatible with Apache Beam's DoFn serialization requirements.

Use case: SMBCollection API needs to convert case classes to GenericRecord
inside transform DoFns to preserve shuffle-free execution. Without this
fix, any case class using @doc annotations fails with:
java.io.NotSerializableException: com.spotify.scio.avro.types.package$doc

This is a minimal, backward-compatible change that has no impact on
existing functionality - it only enables new use cases that require
serializing AvroType instances.

The @doc annotation is used to add documentation metadata to Avro schemas
generated via AvroType.toSchema. However, when AvroType instances are
captured in Beam DoFn closures (e.g., when converting case classes to
GenericRecord inside a transform), the @doc annotation must be serializable.

This change adds 'with Serializable' to the doc annotation class, making
it compatible with Apache Beam's DoFn serialization requirements.

Use case: SMBCollection API needs to convert case classes to GenericRecord
inside transform DoFns to preserve shuffle-free execution. Without this
fix, any case class using @doc annotations fails with:
  java.io.NotSerializableException: com.spotify.scio.avro.types.package$doc

This is a minimal, backward-compatible change that has no impact on
existing functionality - it only enables new use cases that require
serializing AvroType instances.
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.52%. Comparing base (83f43ff) to head (103a9b1).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5881      +/-   ##
==========================================
- Coverage   61.53%   61.52%   -0.02%     
==========================================
  Files         317      317              
  Lines       11663    11662       -1     
  Branches      850      869      +19     
==========================================
- Hits         7177     7175       -2     
- Misses       4486     4487       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

spkrka and others added 2 commits February 5, 2026 18:14
This test verifies that the @doc annotation from scio-avro is
Serializable and can be used with Magnolify's AvroType in map
operations that get serialized as part of Beam DoFns.

The test includes:
- DocAnnotationMapJob: Uses @AvroType.toSchema + @doc, creates records
  in .map(), converts with avroType.to - this would fail without the
  Serializable fix
- NoDocAnnotationMapJob: Control test without @doc - always works

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The standard Scio saveAsAvroFile API uses AvroMagnolifyTypedIO internally,
which also uses .map(avroT.to). This captures the AvroType (including
@doc annotations) in a closure that gets serialized.

This test verifies that the standard API also requires @doc to be
Serializable, confirming that making @doc Serializable is the correct fix.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant