-
Notifications
You must be signed in to change notification settings - Fork 88
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
Add context manager to Txn and DgraphClientStub. #185
base: master
Are you sure you want to change the base?
Conversation
@garylavayou Thank you for the PR. will you be able to rebase the change on the latest master? |
I have synced the forked repo with the latest master. Is that enough? |
Could you also sign the CLA please before we review the code? I have two comments/questions here:
|
@mangalaman93 It would be better if you can add tests to the code, since I currently have no stable test environment. I am also looking forward that you can make the context manager more robust and extend the function with your opinions. |
@garylavayou Thanks for responding back. I am busy with a few other things, I highly doubt if I could spend time writing tests right now. But I will keep this in mind. If you do get more time and opportunity to make changes, please go ahead and keep me posted. Appreciate your time and responding back. |
This PR has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open. |
keep it open please! |
This PR has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open. |
Using Transaction with Context Manager
The Python context manager will automatically perform the "
commit
" action after all queries and mutations have been done and perform "discard
" action to clean the transaction. When something goes wrong in the scope of context manager, "commit
" will not be called, and the "discard
" action will be called to drop any potential changes.or you can directly create a transaction from the
Txn
class.Use context manager to automatically clean resources
Use function call:
Use class constructor:
Note:
client
should be used inside the "with-as
" block. The resources related toclient
will be automatically released outside the block andclient
is not usable anymore.