Skip to content

Conversation

andrewsapw
Copy link

@andrewsapw andrewsapw commented Jul 7, 2025

Description

  • When Pydantic model has field annotated as Optional and without default value or default factory - it still must be explicitly specified
  • When Pydantic model has field annotated as list and has default factory - default factory must be used when initializing model without providing value for this field

Also, fixed test_field_definition_implicit_optional_default test, that checked if Optional field without default / default_factory converts to field with None as default value, although similar msgspec model converts it to field with Empty value

Closes

Partially closes #4232

@andrewsapw andrewsapw changed the title fix: PydanticDTO issues Draft: fix: PydanticDTO issues Jul 7, 2025
@github-actions github-actions bot removed the type/bug label Jul 7, 2025
@andrewsapw andrewsapw changed the title Draft: fix: PydanticDTO issues fix: PydanticDTO issues Jul 7, 2025
@andrewsapw andrewsapw marked this pull request as draft July 7, 2025 20:14
Copy link

codecov bot commented Jul 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.38%. Comparing base (1e0dc7c) to head (8807254).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4236      +/-   ##
==========================================
- Coverage   98.38%   98.38%   -0.01%     
==========================================
  Files         348      348              
  Lines       15895    15891       -4     
  Branches     1756     1754       -2     
==========================================
- Hits        15638    15634       -4     
  Misses        121      121              
  Partials      136      136              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Jul 7, 2025

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

@andrewsapw andrewsapw changed the title fix: PydanticDTO issues fix(PydanticDTO): enforce explicit specification for Optional fields and ensure default factory usage for list fields Jul 8, 2025
@andrewsapw andrewsapw marked this pull request as ready for review July 8, 2025 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: PydanticDTO issues
1 participant