-
-
Notifications
You must be signed in to change notification settings - Fork 64
fix: recursively convert nested dicts in model_from_dict #637
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
Open
cofin
wants to merge
2
commits into
litestar-org:main
Choose a base branch
from
cofin:feat/nested-dict-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40b5c3d to
f7be7cf
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #637 +/- ##
==========================================
+ Coverage 80.43% 80.49% +0.06%
==========================================
Files 87 87
Lines 6451 6471 +20
Branches 838 845 +7
==========================================
+ Hits 5189 5209 +20
Misses 998 998
Partials 264 264 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Harshal6927
reviewed
Dec 15, 2025
cofin
commented
Dec 15, 2025
3e0666d to
769377a
Compare
Harshal6927
approved these changes
Dec 19, 2025
…_dict Fixed regression where service.create() failed when passing nested dictionaries for relationship data. The model_from_dict() function now uses SQLAlchemy's class_mapper to detect relationships and recursively converts nested dicts to model instances. Changes: - Add _convert_relationship_value() helper function - Modify model_from_dict() to detect RelationshipProperty attributes - Handle one-to-one, one-to-many, and many-to-many relationships - Preserve existing model instances in mixed lists - Add 17 comprehensive unit tests for nested dict handling
Signed-off-by: Cody Fincher <[email protected]>
769377a to
5cd8cec
Compare
JacobCoffee
approved these changes
Dec 21, 2025
| converted_data[attr_name] = _convert_relationship_value( | ||
| value=value, | ||
| related_model=related_model, | ||
| is_collection=attr.uselist or False, |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldnt you just do attr.uselis since itd always be a bool
Suggested change
| is_collection=attr.uselist or False, | |
| is_collection=attr.uselist, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #556 - Regression where
service.create()failed when passing nested dictionaries for relationship data.Changes
_convert_relationship_value()helper function to handle relationship conversionmodel_from_dict()to detectRelationshipPropertyattributes using SQLAlchemy'sclass_mapperExample Usage
Tests Added
Test plan
_sync.pyfiles