Skip to content

Ignore serde attributes specta does not model (fixes remote = "Self")#2

Merged
agasparovic merged 1 commit into
mainfrom
serde-unknown-attribute-tolerance
Jul 4, 2026
Merged

Ignore serde attributes specta does not model (fixes remote = "Self")#2
agasparovic merged 1 commit into
mainfrom
serde-unknown-attribute-tolerance

Conversation

@agasparovic

Copy link
Copy Markdown

When the serde feature is enabled, parse_container_meta / parse_variant_meta / parse_field_meta return Ok(()) for serde attribute keys they do not recognize without consuming the attribute's value. syn's parse_nested_meta then hits the unconsumed = value tokens and fails the whole derive with expected ,``, so the type silently loses its Type impl and downstream crates fail with "the trait `specta::Type` is not implemented".

Any legal serde name-value or list attribute outside the subset specta models triggers this: container remote / bound / expecting, variant bound, field getter. The one that bit us is #[serde(remote = "Self")] on FlightData in the fltsci repo - the pattern that makes serde emit its derived serialize/deserialize functions as inherent items so the trait impls can be hand-written (migrate-then-parse for the durable JSON schema versioning design). Building flights_api alone worked, because nothing there enables specta-macros/serde; any build including specta-serde (DX bindings, payload-compatibility checker, rust-analyzer workspace checks) failed.

Fix: an else branch in each of the three parsers that consumes and discards the value (= <expr> or a parenthesized list). serde validates its own attribute namespace - a typo still fails the serde derive itself - so specta's job is only to skip what it does not model, including attributes serde adds in the future.

Tests: tests/tests/serde_unknown_attrs.rs covers all five attributes above and asserts the exported shape is unaffected. Before the fix, that file fails to compile with five expected ,`` errors. Also verified end-to-end with a scratch crate mirroring the fltsci setup (serde_with::apply + `Type` derive + `remote = "Self"` + hand-written trait impls delegating to the inherent functions, with `specta-serde` in the graph): round-trip works and `PhasesFormat` exports the correct phase-specific shapes.

The serde attribute parsers returned Ok for unknown keys without consuming
their value, so syn's parse_nested_meta failed the whole derive with
"expected `,`" on any name-value or list attribute specta does not model -
container remote/bound/expecting, variant bound, field getter - whenever the
serde feature is enabled. serde validates its own attribute namespace, so
specta's job is to skip what it does not understand: consume the value (or
parenthesized list) and move on.
@agasparovic agasparovic merged commit ae5cd84 into main Jul 4, 2026
5 checks passed
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