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

Autocommit mode #917

Open
wants to merge 7 commits into
base: master
from
Open

Autocommit mode #917

wants to merge 7 commits into from

Conversation

@gma2th
Copy link
Contributor

@gma2th gma2th commented Jul 22, 2018

Description

Add autocommit mode.
Add on error rollback.
When autocommit_mode is set to false, users can manually commit or rollback the current transaction.
When on_error_rollback is set to true, if a statement in a transaction block generates an error, the error is ignored and the transaction continues.
In order to deactivate autocommit for users transactions, without messing up with intern pgcli transactions, we better use two different connections.
Requested here #410

Limitation

Users are not able to activate/disable autocommit from the UI.
Autocommit has to be activated in order to use on error rollback.
No tests to cover the change.

Ressource

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
@gma2th gma2th force-pushed the gma2th:master branch from bc96f4d to 31b07bc Jul 24, 2018
@j-bennet
Copy link
Contributor

@j-bennet j-bennet commented Jul 25, 2018

Unit tests are failing with a unicode error there in tests/test_pgexecute.py. Are you able to run them locally (running py.test in pgcli directory)?

@lelit
Copy link
Contributor

@lelit lelit commented Jul 26, 2018

I think that the reason of the failure is that the new get_new_connection() method should install the same typecasters as done by connect()... Maybe some refactor could be made, to avoid duplicating basically the same code to create the connection.

Also, I'm not sure if those typecasters should be moved only onto the new user_conn: I would expect that only user queries will involve JSON values...

Finally, in the method execute_normal_sql() (the only place where the new user_conn gets used), there's a loop that pops possible notices: shouldn't it targeting the same user_conn connection?

@gma2th gma2th force-pushed the gma2th:master branch from 31b07bc to 1eb0b5e Jul 31, 2018
@gma2th gma2th force-pushed the gma2th:master branch from 1eb0b5e to 1bda1a3 Jul 31, 2018
@codecov-io
Copy link

@codecov-io codecov-io commented Jul 31, 2018

Codecov Report

Merging #917 into master will decrease coverage by 0.51%.
The diff coverage is 59.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #917      +/-   ##
==========================================
- Coverage   84.57%   84.05%   -0.52%     
==========================================
  Files          21       21              
  Lines        2463     2496      +33     
==========================================
+ Hits         2083     2098      +15     
- Misses        380      398      +18     
Impacted Files Coverage Δ
pgcli/pgexecute.py 78.90% <58.73%> (-3.64%) ⬇️
pgcli/main.py 77.08% <66.66%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f0be9d...59f0c77. Read the comment docs.

@gma2th gma2th force-pushed the gma2th:master branch from 1bda1a3 to afa8f89 Jul 31, 2018
@gma2th
Copy link
Contributor Author

@gma2th gma2th commented Jul 31, 2018

Thank you for having a look at this PR.
I fixed the unicode error (due to typecasters) and notices, thank you.
It definitely need some refactor, in order to init all connections in the same place. I can have a look in the next days. This could be done in another PR, up to you.
[Edit] Made the refactor, any feedback welcome. Idk why pep8radius doesn't produce any output locally...

@gma2th gma2th force-pushed the gma2th:master branch 6 times, most recently from b36bd23 to ec4511c Jul 31, 2018
@gma2th gma2th force-pushed the gma2th:master branch from 9712e97 to e2e3917 Aug 5, 2018
@amjith
Copy link
Member

@amjith amjith commented Nov 18, 2018

@gma2th I looked through the PR and I have 2 questions. Let me preface these comments by saying, I would like to minimize the number of configuration options in pgcli. It is wise to choose sensible defaults wherever possible.

  1. What is the purpose of surfacing the autocommit mode as a config? Is there an advantage in disabling autocommit mode? From my basic understanding we want to have the autocommit mode enabled at all times and the user can specify the BEGIN command to explicitly start a transaction.

  2. Why is the on_error_rollback set to off by default? Wouldn't it make sense to have that on all the time?

@amjith
Copy link
Member

@amjith amjith commented Nov 18, 2018

Hrm. Even when I set the on_error_rollback set to True it ends up aborting the transaction. I haven't traced the issue yet. Can you please verify if it works for you?

@Gollum999
Copy link
Contributor

@Gollum999 Gollum999 commented Sep 27, 2019

Any updates on this? I've been interested in this feature for quite a while.

@samskeller
Copy link

@samskeller samskeller commented Mar 19, 2020

@amjith @gma2th any updates on getting this through? Not being able to turn off autocommit for pgcli is basically a dealbreaker for me and many others who want some safety from fat-fingering!

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

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.