Improve validation and failure modes in with_parent() - #13586
Open
VimalN2005 wants to merge 1 commit into
Open
VimalN2005 wants to merge 1 commit into
VimalN2005 wants to merge 1 commit into
Conversation
Add early validation in with_parent() and _with_parent() to ensure: - instance is a mapped instance and not None - prop is a valid relationship property or queryable attribute - instance is compatible with the parent mapper of the relationship Fixes: sqlalchemy#6860
Collaborator
|
Thanks! Issue #6860 is now marked code review in progress and no longer open for pull requests, so this pull request holds the review for it and another one won't land on top of your work. If this pull request is abandoned, a maintainer can put open for pull requests back on #6860 to reopen it to others. |
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
Fixes: #6860
Description
Improve error reporting and validation for
with_parent():with_parent()ensuringinstanceis notNoneand is a mapped instance, raising a descriptiveArgumentError._with_parent()and_optimized_compare()ensuringinstancematches the parent mapper of the provided relationship property (not state.mapper.isa(mapper)), raising anArgumentErrorwhen mismatched entities are passed (e.g.,with_parent(a1, B.a)whereB.abelongs toB).propertyto ensure it is a valid relationship attribute or queryable property, raisingArgumentErrorrather than falling through to an unhandledAttributeError.Checklist
test/orm/test_query.py(ParentTest)ParentTesttests and existingwith_parenttests pass cleanlydoc/build/changelog/unreleased_21/6860.rst