Repository navigation
fix: use relation name as key when loading select_related child in from_row - #1829
Open
moneebullah25 wants to merge 2 commits into
Open
moneebullah25 wants to merge 2 commits into
moneebullah25 wants to merge 2 commits into
Conversation
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 #1827
Problem
select_relatedon a relation raisesModelErrorwhen a column alias on the related model equals the relation name. InModelRow.from_rowthe loaded child was stored undermodel_cls.get_column_name_from_alias(related), which translates the relation name through the related model's column aliases. If a column there hasname=equal to the relation name, the child ended up under that field's key instead of the relation's.Fix
Store the child under
related(the relation name) directly inormar/models/model_row.py.Tests
Added
tests/test_relations/test_relation_name_equals_column_alias.pycovering forward ForeignKey, reverse relation and ManyToMany where a column alias equals the relation name.Checks run
ruff format --checkandruff check(ruff 0.16.10) on the changed files: passmypy ormar tests/test_relations/test_relation_name_equals_column_alias.py --ignore-missing-imports: no issuespytest tests/test_relations tests/test_queries(sqlite): 202 passed, 24 skippedflake8 ormarandmkdocs build: not run (no documentation changes)