-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
chore: Remove unnecessary autoflush from tagging and key/value workflows #26009
chore: Remove unnecessary autoflush from tagging and key/value workflows #26009
Conversation
59c2463
to
2bba0c5
Compare
session = Session(bind=connection) | ||
|
||
try: | ||
with Session(bind=connection) as session: |
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.
Opting for a context manager which closes the session on exit.
@@ -111,7 +111,7 @@ class TaggedObject(Model, AuditMixinNullable): | |||
tag = relationship("Tag", back_populates="objects", overlaps="tags") | |||
|
|||
|
|||
def get_tag(name: str, session: Session, type_: TagType) -> Tag: | |||
def get_tag(name: str, session: orm.Session, type_: TagType) -> Tag: |
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.
We redefine the Session
class on line 38 so the previous type hint wasn't completely accurate.
2bba0c5
to
03e5729
Compare
@john-bodley so those closed sessions in the event handlers were caused by those explicit |
@villebro I think the error you might have been seeing, per what I was witnessing earlier when trying the
i.e., it was transaction as opposed to session related. The reason being (as mentioned in Slack) was that in the SQLAlchemy event documentation it states:
So when trying to leverage the Flask-SQLAlchemy session—via either Note in [SIP-99B] Proposal for (re)defining a "unit of work" this type of operation will not be allowed because it violates the "unit of work". |
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.
Very nice 👍 So I assume one of the next steps is to start moving those event listener based mutations into the parent commands?
@john-bodley got it, this is all finally starting to make sense. Thanks for taking this on - once finished, this will have a big positive impact on the backend code quality, performance, maintainability etc.. |
@villebro in terms of next steps, today's discussion (in conjunction with this PR) helped to solidify what is viable with SQLAlchemy event handlers and thus I updated SIP-99B with regards to how this should be handled moving forward. The TL;DR is ideally we should move said logic either to the database (if said events previously were handling logic which could be captured via a |
SUMMARY
This PR addresses this comment associated with #24776. After speaking with @michael-s-molina and @villebro it seems like the
autoflush
logic was likely not necessary.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
CI.
ADDITIONAL INFORMATION