Skip to content

fix: eager-load workspace.account in SocialAccountObserver to prevent lazy loading crash - #259

Merged
paulocastellano merged 2 commits into
mainfrom
fix/social-account-observer-lazy-load-crash
Aug 9, 2026
Merged

fix: eager-load workspace.account in SocialAccountObserver to prevent lazy loading crash#259
paulocastellano merged 2 commits into
mainfrom
fix/social-account-observer-lazy-load-crash

Conversation

@paulocastellano

Copy link
Copy Markdown
Contributor

Summary

  • SocialAccountObserver::notifyOnboarding() read $socialAccount->workspace?->account without eager-loading workspace, which lazy-load-strict mode rejects once Builder::hydrate() batches 2+ distinct SocialAccount rows in the same query (only then does it flip preventsLazyLoading on the models).
  • Fixed at the source: notifyOnboarding() now calls $socialAccount->loadMissing('workspace.account') before touching the relation, so no caller needs to remember to eager-load it.
  • Added a regression test that hydrates 2 SocialAccount rows in one query and updates each — reproduces LazyLoadingViolationException before the fix, passes after.

Closes #255

Test plan

  • php artisan test --compact tests/Feature/Observers/SocialAccountObserverTest.php — 5 passed
  • php artisan test --compact --parallel --filter="Observers|VerifyUpcomingPostConnections" — 48 passed
  • vendor/bin/pint --dirty --format agent — clean

…y-loading protection

Reflects that SocialAccountObserver::notifyOnboarding() now self-heals via loadMissing().
@paulocastellano
paulocastellano merged commit f019053 into main Aug 9, 2026
5 checks passed
@paulocastellano
paulocastellano deleted the fix/social-account-observer-lazy-load-crash branch August 9, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SocialAccountObserver::notifyOnboarding() lazy-loads workspace — crashes when 2+ SocialAccount rows are batch-hydrated

1 participant