-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration defaults do not match serde #4000
Comments
We're going to have to go the custom macro route. The issue is that the serde auto defaulting mechanism will only work where all fields are optional. |
This was
linked to
pull requests
Oct 10, 2023
BrynCooke
pushed a commit
that referenced
this issue
Oct 10, 2023
There are two types of serde defaulting: * container * field Container level defaulting will use an instance of the default implementation and take missing fields from it. Field level defaulting uses either the default implementation or optionally user supplied function to initialize missing fields. When using field level defaulting it is essential that the Default implementation of a struct exactly match the serde annotations. A test checks to ensure that field level defaulting is not used in conjunction with a Default implementation and gives guidance on resolution. Fixes #4000
BrynCooke
added a commit
that referenced
this issue
Oct 11, 2023
There are two types of serde defaulting: * container * field Container level defaulting will use an instance of the default implementation and take missing fields from it. Field level defaulting uses either the default implementation or optionally user supplied function to initialize missing fields. When using field level defaulting it is essential that the Default implementation of a struct exactly match the serde annotations. A test checks to ensure that field level defaulting is not used in conjunction with a Default implementation and gives guidance on resolution. *Description here* Fixes #4000 <!-- start metadata --> --- **Checklist** Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review. - [ ] Changes are compatible[^1] - [ ] Documentation[^2] completed - [ ] Performance impact assessed and acceptable - Tests added and passing[^3] - [ ] Unit Tests - [ ] Integration Tests - [ ] Manual Tests **Exceptions** *Note any exceptions here* **Notes** [^1]: It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. [^2]: Configuration is an important part of many changes. Where applicable please try to document configuration examples. [^3]: Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. Co-authored-by: bryn <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When writing configuration structures it is essential that serde defaults agree with the rust Default implementation.
Failure to do this means that users will get very unexpected results depending on where their configuration stops and defaulting starts.
This isn't going to be fixed in serde serde-rs/serde#2622, so it is on us to ensure that things match.
To complete this we need:
Default
correctly for structs that dreiveDeserialize
.OR:
This could be seen as a serious security/stability bug, as users will not be able to rely on the default in the documentation actually taking place.
The text was updated successfully, but these errors were encountered: