fix: add was_attribute_set() guard to relationship loop in update()#685
Merged
cofin merged 1 commit intolitestar-org:mainfrom Mar 3, 2026
Merged
fix: add was_attribute_set() guard to relationship loop in update()#685cofin merged 1 commit intolitestar-org:mainfrom
was_attribute_set() guard to relationship loop in update()#685cofin merged 1 commit intolitestar-org:mainfrom
Conversation
Contributor
Author
|
Hi @cofin, let me know if I can do anything in order to fix the CI here. Seems to be unrelated to the changes from the PR. Tests were passing locally. |
Member
|
@sohbit it may be a transient error. I've triggered a retry and will keep an eye on it. |
Partial updates using model instances (e.g. Model(id=..., name='new')) were silently clearing relationships because SQLAlchemy auto-initializes unset relationship attributes to None/[], which then passed the 'is not MISSING' check and got written through to the DB. This adds the same was_attribute_set() guard that already protects the column loop to the relationship loop, so only explicitly set relationships are copied during update(). Closes litestar-org#684
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #685 +/- ##
==========================================
- Coverage 80.69% 80.67% -0.02%
==========================================
Files 99 99
Lines 8173 8177 +4
Branches 1119 1121 +2
==========================================
+ Hits 6595 6597 +2
- Misses 1247 1249 +2
Partials 331 331 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
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.
Description
Partial updates using model instances (e.g.
Model(id=..., name='new')) were silently clearing relationships because SQLAlchemy auto-initializes unset relationship attributes toNone/[], which then passed the 'is not MISSING' check and got written through to the DB.This adds the same
was_attribute_set()guard that already protects the column loop to the relationship loop, so only explicitly set relationships are copied duringupdate().Closes
update()missingwas_attribute_set()guard on relationship loop which silently clears relationships during partial updates #684