Repository navigation
fix: Fix deserialization of collections of serverOnly models - #4433
Conversation
Fixed bug where List<ServerOnlyModel> deserialization was not generated on server side. Root cause: shouldSerializeField() returned false for serverOnly fields even on server, preventing field types from being included in deserialization generation. Added test case reproducing the issue with Article and ArticleList serverOnly models. Co-authored-by: marcelomendoncasoares <[email protected]>
Fixed bug where List<ServerOnlyModel> deserialization was not generated on server side. Root cause: allFieldsToGenerateSerialization used shouldSerializeField() which filtered out serverOnly fields. Changed to use shouldIncludeField() instead, which correctly includes serverOnly fields on the server while excluding them on the client. shouldSerializeField() is specifically for protocol communication (toJson/toJsonForProtocol), while shouldIncludeField() is for determining which fields exist in generated code. Added test case with Article and ArticleList serverOnly models reproducing the issue. Co-authored-by: marcelomendoncasoares <[email protected]>
marcelomendoncasoares
left a comment
There was a problem hiding this comment.
Fix is correct. Now also add tests on tools/serverpod_cli/test/generator/dart for both client and server to attest that the deserialization entry exist on the protocol file. After this, run the generate_all_parallel script again and await until all have finished to fix a broken package after the last generate. Do this in separate commits.
Added tests in tools/serverpod_cli/test/generator/dart to verify: - Server protocol includes deserialization for List<ServerOnlyModel> - Client protocol excludes deserialization for serverOnly models Tests confirm the fix works correctly for both client and server code generation. Co-authored-by: marcelomendoncasoares <[email protected]>
Regenerated all protocol files after the fix. Changes include: - serverpod_auth_bridge: Added Set<String> deserialization - serverpod_auth_idp: Added Map<String, String> deserialization - serverpod_auth_migration: Fixed empty protocol file with complete definitions All packages now have proper deserialization entries for their field types. Co-authored-by: marcelomendoncasoares <[email protected]>
Done. Added protocol generation tests for both client and server in commits ac59628 and regenerated all packages with generate_all_parallel in commit 15b68e9. The broken serverpod_auth_migration package protocol file has been fixed. |
serverOnly models
SandPod
left a comment
There was a problem hiding this comment.
LGTM!
Two minor suggestions to improve tests.
|
@copilot Please address the last review comments on the tests. |
- Simplified protocol tests to check for 'Article' string presence/absence instead of regex patterns - Made tests more resilient to implementation changes (e.g., if->switch refactoring) - Reorganized server_only_model_list_deserialization_test into separate Given groups for better clarity Co-authored-by: marcelomendoncasoares <[email protected]>
Server-side deserialization failed for collections of
serverOnlymodels (e.g.,List<Article>whereArticleisserverOnly: true), throwingDeserializationTypeNotFoundException.Root cause:
allFieldsToGenerateSerializationusedshouldSerializeField()to collect field types for deserialization generation. This method excludes serverOnly fields (correct for protocol communication) but prevented their collection types from being generated.Fix: Use
shouldIncludeField()instead, which correctly includes serverOnly fields on server while excluding them on client.Impact: One-line change in
library_generator.dart. No changes to serialization behavior (toJson/toJsonForProtocolstill exclude serverOnly fields).Testing improvements: Protocol generation tests simplified to check for model name presence/absence instead of regex patterns, making them more resilient to implementation changes. Runtime tests reorganized into separate
Givengroups for better clarity.Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.Breaking changes
None.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.