- Notifications
You must be signed in to change notification settings - Fork 1
feat: transactions management #18
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
Conversation
| for transaction in self.transactions: | ||
| transaction.rollback() | ||
| | ||
| self.transactions = [] |
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.
Commiting and rollbacking all the pending transactions of this connection
google/cloud/spanner_dbapi/cursor.py Outdated
| | ||
| self._res = self.transaction.execute_sql(sql) | ||
| self._itr = PeekIterator(self._res) | ||
| return |
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.
Starting a transaction, if no yet started, or the last one is already commited/rollbacked. Then running SQL request in the current transaction.
| | ||
| def tearDownModule(): | ||
| if CREATE_INSTANCE: | ||
| Config.INSTANCE.delete() |
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.
All of the above preparations code is taken from the original Spanner system tests
tests/system/test_system.py Outdated
| # TODO: Implement this method | ||
| pass | ||
| with self._db.snapshot() as snapshot: | ||
| snapshot.execute_sql("DELETE FROM contacts WHERE true") |
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.
Clearing the data from the table after every test
| @mf2199, I've written the code in more civilized manner and added a system test. Locally everything is working fine so far. |
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.
Just a couple of suggestions, but looks good overall.
| self.transactions = [] | ||
| | ||
| self.is_closed = False | ||
| self.autocommit = True |
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.
This is not something we'd expect the users to change on the fly. Thus, would it make more sense to have it read-only, optionally assignable via the constructor, e.g.:
def __init__(self, instance, database, autocommit=True): ... self._autocommit = autocommit and if necessary, add a property getter, WDYT?
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 had a word about it with Chris some time ago, and decided to use a property. It can be found in our meetings notes.
We don't have any mentions of autocommit mode in PEP 249, so it seems like we should ask the Java implementation about it:
https://github.com/googleapis/java-spanner-jdbc/blob/cedd167c5973fe50e0205ae641f6580ebd627884/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java#L81-L82
Thus, there will be both setter and getter of this property
…n, return used sessions back to the pool
…n-spanner-django into transactions_retry
…n-spanner-django into transactions_retry
No description provided.