fix(#64): cartesian product in reln reflection to non-versioned classes#154
Merged
winwinashwin merged 1 commit intomainfrom Dec 28, 2025
Merged
fix(#64): cartesian product in reln reflection to non-versioned classes#154winwinashwin merged 1 commit intomainfrom
winwinashwin merged 1 commit intomainfrom
Conversation
ashish16052
approved these changes
Dec 28, 2025
| # For many-to-many relationships, we also need to include the secondary join | ||
| if direction.name == "MANYTOMANY" and self.property.secondaryjoin is not None: | ||
| criteria = sa.and_(criteria, reflector(self.property.secondaryjoin)) | ||
| return criteria |
Collaborator
There was a problem hiding this comment.
you can have this unit test in tests/relationships/test_non_versioned_classes.py
def test_no_cartesian_product_with_multiple_unrelated_tags(self):
# Create an article with one tag
article = self.Article(name="Some article")
tag1 = self.Tag(name="tag1")
article.tags.append(tag1)
self.session.add(article)
self.session.commit()
# Create another article with a different tag
article2 = self.Article(name="Another article")
tag2 = self.Tag(name="tag2")
article2.tags.append(tag2)
self.session.add(article2)
self.session.commit()
# Ensure the first article's version only has its own tag, not all tags
assert len(article.versions[0].tags) == 1
assert article.versions[0].tags[0] == tag1
In many-to-many relationships when one of the classes is not versioned, we were not including the secondaryjoin in the filter criteria leading to a cartesian product.
25a80f6 to
179df4f
Compare
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: #64