Conversation
abdusco
force-pushed
the
fix/factory-existing-relation-cycle
branch
from
September 6, 2026 14:18
cc1c2b6 to
0eb8740
Compare
abdusco
force-pushed
the
fix/factory-existing-relation-cycle
branch
from
September 6, 2026 14:51
1126047 to
9af65fe
Compare
abdusco
marked this pull request as ready for review
September 6, 2026 15:06
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.
Problem
Factories can accept an existing model as a relationship. If that model has its relationships loaded, and those relationships point back to it, factory construction can follow the circular graph indefinitely.
For example, an existing
Usercontaining loadedVideos, where eachVideopoints back to that sameUser, causes a stack overflow when the user is supplied as an existing relationship for a new video.Factory APIs should safely accept loaded bidirectional model graphs. They should preserve the existing relationship where needed, but stop following a model that has already been encountered during the same construction.
Fix
Track models encountered while converting existing relationship graphs, regardless of which factory API begins the conversion. Once a model has already been visited, stop traversing through its loaded relationships.
Regression Test
Adds a generated, no-database test using the existing
users/videosfixture:The test builds a minimal in-memory relationship cycle and verifies that supplying the existing user relationship completes rather than crashing the test process.
Fixes #761.