Skip to content

fix: add was_attribute_set() guard to relationship loop in update()#685

Merged
cofin merged 1 commit intolitestar-org:mainfrom
sohbit:main
Mar 3, 2026
Merged

fix: add was_attribute_set() guard to relationship loop in update()#685
cofin merged 1 commit intolitestar-org:mainfrom
sohbit:main

Conversation

@sohbit
Copy link
Copy Markdown
Contributor

@sohbit sohbit commented Feb 27, 2026

Description

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

@sohbit
Copy link
Copy Markdown
Contributor Author

sohbit commented Mar 2, 2026

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.

@cofin
Copy link
Copy Markdown
Member

cofin commented Mar 3, 2026

@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-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.67%. Comparing base (c98a33e) to head (f44f439).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
advanced_alchemy/repository/_sync.py 0.00% 2 Missing ⚠️
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.
📢 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.

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.

LGTM

@cofin cofin merged commit f5e02bb into litestar-org:main Mar 3, 2026
19 checks passed
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.

3 participants