Skip to content

feat(msgspec_dto): include msgspec tagged union field#4671

Draft
abdulhaq-e wants to merge 1 commit intolitestar-org:mainfrom
abdulhaq-e:include_msgspec_tag_field
Draft

feat(msgspec_dto): include msgspec tagged union field#4671
abdulhaq-e wants to merge 1 commit intolitestar-org:mainfrom
abdulhaq-e:include_msgspec_tag_field

Conversation

@abdulhaq-e
Copy link
Copy Markdown
Contributor

When using msgspec tagged union, it is sometimes desirable to include the tag field in the DTO. This wasn't supported.

The current implementation unconditionally includes this field. I believe it's a good default option, however I think we should introduce a custom MsgspecDTOConfig (similar to what we had for SQLAlchemy) which can control this behaviour.

This code was also generated using AI but this sometimes it's an area of the code base I'm more familiar with.

I've created it as draft to discuss having MsgspecDTOConfig and the flag and for any further edits.

@github-actions github-actions bot added area/dto This PR involves changes to the DTOs size: small type/feat pr/external Triage Required 🏥 This requires triage labels Apr 4, 2026
@abdulhaq-e
Copy link
Copy Markdown
Contributor Author

This is similar to #3742 which added the tag field to open api. Perhaps since it's always added to Open api and since this is the new v3, it might be okay to just introduce it unconditionally. One can then exclude it if needed using exclude in DTOConfig

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.35%. Comparing base (69a1ad9) to head (2a14993).

Files with missing lines Patch % Lines
litestar/dto/msgspec_dto.py 76.47% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4671      +/-   ##
==========================================
+ Coverage   67.33%   67.35%   +0.01%     
==========================================
  Files         292      292              
  Lines       14941    14957      +16     
  Branches     1676     1677       +1     
==========================================
+ Hits        10061    10074      +13     
- Misses       4743     4746       +3     
  Partials      137      137              

☔ 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.

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/external size: small Triage Required 🏥 This requires triage type/feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant