fix: recompute changed? after setup_managed_belongs_to_relationships#2647
Merged
zachdaniel merged 1 commit intoash-project:mainfrom Mar 24, 2026
Merged
Conversation
When manage_relationship is called from before_transaction or before_action hooks on update actions, the FK attribute gets set via force_change_attribute inside setup_managed_belongs_to_relationships. However, the changed? flag was computed before this point, so it remained false, causing the DB update to be skipped entirely. The related record was created but the source record's FK was never persisted. Recompute changed? after setup_managed_belongs_to_relationships returns so that FK changes from managed relationships are detected.
2 tasks
Contributor
Author
|
Companion regression tests: ash-project/ash_postgres#727 |
zachdaniel
approved these changes
Mar 24, 2026
Contributor
|
🚀 Thank you for your contribution! 🚀 |
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.
Summary
manage_relationshipis called frombefore_transactionorbefore_actionhooks on update actions, thechanged?flag was computed beforesetup_managed_belongs_to_relationshipsruns, so it remainedfalseeven after the FK was set viaforce_change_attributecondbranch to skip the DB update entirely — the related record was created but the source record's FK was never persistedchanged?aftersetup_managed_belongs_to_relationshipsreturns, so FK changes from hook-added managed relationships are detectedCompanion PR: ash-project/ash_postgres — regression tests (will link once created)
Test plan
test/manage_relationship_test.exsfor update +before_transactionhook with ETS data layer