-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: two usability issues with sqlalchemy #354
Conversation
1de28b4
to
38c7a93
Compare
bef36f7
to
f1eabb6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just left a small comment.
def test_can_build_select(): | ||
""" | ||
This is a very minimal test case that failed when doing | ||
some development with the extension. | ||
The nature of the vectorizer_relationship being a descriptor messes | ||
with sqlalchemys relationship resolution. | ||
It was previously using `backref` to propagate the parent field, | ||
which is resolved later and an immediate access | ||
to build queries like this would fail. | ||
""" | ||
select(Document.content_embeddings).options( | ||
joinedload(Document.content_embeddings.parent) # type: ignore | ||
) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's intended not to have assertions here, to just verify it builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it was throwing an exception before 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test for issue 1 added somewhere? (I might have missed it)
f1eabb6
to
beafcc3
Compare
@cevian yes the select test covers this too, because the same file has two models with |
I am fixing two quite annoying issues with the SQLAlchemy integration in this PR:
It wasn't possible to have the same field name configured on two different entities. So you can't have
content_embeddings
twice, because the name was colliding in the Mapper configuration. So I changed the dynamically generated Model name to contain the parent Model.The way we were configuring the relationship into the other direction via
backref
was somewhat lazily evaluated and is also no longer recommended by SQLAlchemy. It's considered "legacy". I changed it with some back and forth to be simply two relationships in both directions and added aparent_kwargs
field that allows to configure the relationship into the reverse direction.