Skip to content

fix: Generate deserializers for container types of exception and sealed parent fields - #5946

Merged
marcelomendoncasoares merged 3 commits into
serverpod:mainfrom
BiAksoy:fix/exception-list-field-deserializer
Nov 5, 2026
Merged

marcelomendoncasoares merged 3 commits into
serverpod:mainfrom
BiAksoy:fix/exception-list-field-deserializer

Conversation

@BiAksoy

@BiAksoy BiAksoy commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

When a container field such as List<FieldProblem> is declared on a serializable exception, or on the sealed parent of a hierarchy, and no other class declares a field of the same type, the generated Protocol.deserialize has no branch for it. Decoding the object fails with No deserialization found for type List<FieldProblem>.

The field types that get a branch are collected from unsealedModels.whereType<ModelClassDefinition>():

final allFieldsToGenerateSerialization = unsealedModels
.whereType<ModelClassDefinition>()
.expand((m) => m.fields)
.where((f) => f.shouldIncludeField(serverCode))
.distinct();

The type filter leaves out exceptions, and unsealedModels leaves out every sealed class, whose own fields are the only place the parent's fields are listed.

This PR collects the fields from allModels.whereType<ClassDefinition>() instead. ClassDefinition is sealed, with ModelClassDefinition and ExceptionClassDefinition as its only subclasses, and allModels is the list unsealedModels is filtered from, so the change adds exactly the fields of exceptions and of sealed classes. Enums are not ClassDefinitions and are unaffected. Fields are still filtered by shouldIncludeField and deduplicated as before. The class branches still come from unsealedModels, so sealed classes get no branch of their own, as before.

With the steps from #5945:

Before:

decode failed: No deserialization found for type List<FieldProblem>
decode failed: No deserialization found for type List<Tag>

After:

decoded: SomeRefused(message: refused, problems: [{"__className__":"FieldProblem","field":"name","message":"required"}])
decoded: {"__className__":"TextPost","tags":[{"__className__":"Tag","name":"news"}],"text":"hello"}

The commits are split into the fix with its generator tests, the test server models and test, and the regenerated code.

Tests:

  • The server and client generator tests check that the List branches are generated for a List field of a model declared on an exception (protocol_test.dart), on a sealed parent model (inheritance_protocol_test.dart) and on a sealed parent exception (inheritance_exception_protocol_test.dart). All of them fail on main. With the type filter changed but unsealedModels kept, the exception tests pass and the four sealed ones still fail.
  • The test server has an exception, ExceptionWithModelList, with a List<ExceptionDetail> field, and a sealed SealedListParent with a List<SealedListItem> field and a child, SealedListChild. Neither list type is used elsewhere. model_list_field_deserialization_test.dart decodes both with the server protocol and, by class name, with the client protocol. With the test server generated from main's generator, the four tests fail with the error above.
  • util/generate_all with the change regenerates every other package identically. In the test server and client protocols, the only change besides the new models is that the existing List<String> branch moves up, because ExceptionWithData.errorFields now also contributes it.
  • The full serverpod_cli suite and the test server's unit tests pass locally, and dart analyze --fatal-infos is clean for the CLI, the test server and the test client.

Fixes #5945.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

None.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@BiAksoy

BiAksoy commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

The failing job looks unrelated to this change.

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this one, @BiAksoy! 🚀

@marcelomendoncasoares
marcelomendoncasoares merged commit 9e02d16 into serverpod:main Nov 5, 2026
959 of 960 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated protocol has no deserializer for a List field declared on an exception or a sealed parent

2 participants