Repository navigation
Conversation
Key-only instances fill required relations of the target with -1 placeholders. When the relation points back at a model whose placeholder is already being built (a required self-reference, or a cycle of required relations), the placeholder needed another placeholder of its own without end and raised RecursionError on Node(parent=1) and when loading such rows. Leave those relations unset instead. Fixes ormar-orm#2061
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance1 warning, 1 note
Comparing |
This branch has not been deployed
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.
Fixes #2061
key_only_instancefills every required relation of the target with a-1placeholder built by calling itself on the related model. For a required self-reference (or any cycle of required relations) the placeholder needs a placeholder of its own, soNode(parent=1)and loading such a row hitRecursionError.The fix tracks the models already being built in the current chain and leaves a relation unset when it points back at one of them. The nested placeholder then behaves like the nullable case (
node.parent.parent is None), while non-cyclic required relations still get their placeholders as before.Tests (
tests/test_relations/test_required_self_reference.py):Node(parent=1)for a required self-referenceChicken.egg/Egg.chicken)get+select_related("parent").getround-trip against the databaseAll three fail on
masterwithRecursionErrorand pass with the change. Full suite on SQLite: the only failures are the 7test_pool_resetMySQL cases that needasyncmy/aiomysql, same as onmaster.