Skip to content
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

feat(DTO): Support extra="forbid" model config for PydanticDTO #3691

Merged
merged 2 commits into from
Aug 24, 2024

Conversation

provinzkraut
Copy link
Member

@provinzkraut provinzkraut commented Aug 24, 2024

Set forbid_unkown_fields=True for PydanticDTOs where the Pydantic model has an extra="forbid" config.


  • Add a new get_config_for_model_type method to AbstractDTO, that allows to customise the base config defined on the DTO factory for a specific model type
  • Use get_config_for_model_type to set forbid_unkown_fields=True for Pydantic models that use the `extra="forbid" config

Depends on #3690. Don't merge before that one :)

@provinzkraut provinzkraut requested review from a team as code owners August 24, 2024 11:01
@github-actions github-actions bot added area/dto This PR involves changes to the DTOs size: small type/feat labels Aug 24, 2024
@provinzkraut provinzkraut added do not merge Don't merge this and removed size: small type/feat area/dto This PR involves changes to the DTOs labels Aug 24, 2024
@provinzkraut
Copy link
Member Author

@peterschutt to keep you in the loop a bit. This isn't really merging configurations, but it's a step in the right direction and at least allows per-model dynamic configs. I think this should help to handle a few of the use cases of config merging already.

Copy link

codecov bot commented Aug 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.28%. Comparing base (9cff0a4) to head (02b8d44).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3691   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files         329      329           
  Lines       14949    14965   +16     
  Branches     2375     2382    +7     
=======================================
+ Hits        14692    14708   +16     
  Misses        116      116           
  Partials      141      141           

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

@github-actions github-actions bot added area/dto This PR involves changes to the DTOs size: small type/feat labels Aug 24, 2024
@provinzkraut provinzkraut force-pushed the dto/reject-unknown-fields branch 2 times, most recently from 84b26cf to 0c6f60b Compare August 24, 2024 18:28
Base automatically changed from dto/reject-unknown-fields to main August 24, 2024 18:34
@provinzkraut provinzkraut force-pushed the dto/support-pydantic-extra-forbid branch from f7b0abd to 6888c41 Compare August 24, 2024 19:09
@provinzkraut provinzkraut removed the do not merge Don't merge this label Aug 24, 2024
@github-actions github-actions bot added the do not merge Don't merge this label Aug 24, 2024
@provinzkraut provinzkraut force-pushed the dto/support-pydantic-extra-forbid branch from 6888c41 to 02b8d44 Compare August 24, 2024 19:14
Copy link

sonarcloud bot commented Aug 24, 2024

@provinzkraut provinzkraut removed the do not merge Don't merge this label Aug 24, 2024
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3691

@provinzkraut provinzkraut merged commit 60e17cd into main Aug 24, 2024
25 of 26 checks passed
@provinzkraut provinzkraut deleted the dto/support-pydantic-extra-forbid branch August 24, 2024 19:22
@peterschutt
Copy link
Contributor

I think this should help to handle a few of the use cases of config merging already.

Sounds great! Thanks for the ping:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dto This PR involves changes to the DTOs pr/internal size: small type/feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants