Skip to content
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 transactions not being committed #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LeiTi34
Copy link

@LeiTi34 LeiTi34 commented May 29, 2024

I had an issue where I was not able to access the table from a second project. Turns out some transactions were not commited.

This PR fixes this Issue

@@ -320,6 +320,7 @@ def get_messages(self) -> List[BaseMessage]:
with self._connection.cursor() as cursor:
cursor.execute(query, {"session_id": self._session_id})
items = [record[0] for record in cursor.fetchall()]
self._connection.commit()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a transaction need to be committed here? There's no mutation that's done in get_messages

Copy link
Author

@LeiTi34 LeiTi34 Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the transaction is still created and never commits, which can block other operations.

See the first code example in the docs.
There conn.close() closes the transaction.

Another option would be to use Autocommit transactions.

Copy link
Author

@LeiTi34 LeiTi34 Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While doing some research I stumbled on this article, which describes some implications of having not committed transactions.

Basically, it avoids VACUUM marking rows as eligible for reuse, as long as the connection is open.

That means, that if someone builds an application that is rarely restarted using this library, it can grow the size of the DB drastically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants