Skip to content

feat(DTO): Add custom attribute accessor callable#4160

Merged
provinzkraut merged 2 commits intomainfrom
dto-attribute-accessor-fn
May 1, 2025
Merged

feat(DTO): Add custom attribute accessor callable#4160
provinzkraut merged 2 commits intomainfrom
dto-attribute-accessor-fn

Conversation

@provinzkraut
Copy link
Copy Markdown
Member

Add a new attribute_accessor property to AbstractDTO, which can be used by both the codegen and functional backend to access attributes on an object.

This can be useful to implement DTOs for types that do not adhere to the plain protocol of obj.data_field or need to add additional checks, e.g. using obj.related_field.all() on a Django model to access related objects, while ensuring no I/O occurs.

@provinzkraut provinzkraut requested review from a team as code owners May 1, 2025 18:55
@github-actions github-actions bot added area/dto This PR involves changes to the DTOs area/private-api This PR involves changes to the privatized API size: small type/feat pr/internal labels May 1, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented May 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.36%. Comparing base (f3cbf4c) to head (2d4d052).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4160      +/-   ##
==========================================
- Coverage   98.37%   98.36%   -0.01%     
==========================================
  Files         348      348              
  Lines       15864    15871       +7     
  Branches     1752     1754       +2     
==========================================
+ Hits        15606    15612       +6     
  Misses        123      123              
- Partials      135      136       +1     

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

@provinzkraut provinzkraut force-pushed the dto-attribute-accessor-fn branch from 7eeeebb to bc5ec09 Compare May 1, 2025 19:30
Copy link
Copy Markdown
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really simple but adds quite a bit of flexibility!

@provinzkraut provinzkraut enabled auto-merge (squash) May 1, 2025 19:35
@provinzkraut provinzkraut merged commit 91a303a into main May 1, 2025
28 checks passed
@provinzkraut provinzkraut deleted the dto-attribute-accessor-fn branch May 1, 2025 19:38
@github-actions
Copy link
Copy Markdown

github-actions bot commented May 1, 2025

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

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 area/private-api This PR involves changes to the privatized API pr/internal size: small type/feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants