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: CREATE DATABASE with psycopg2 v2.9 #27

Merged
merged 6 commits into from
Aug 30, 2021
Merged

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Aug 30, 2021

Addresses aiidateam/aiida-core#5002 (database cannot be created within a transaction)

See psycopg/psycopg2#941 (comment)

You can see the fix working, going from fe7f8ee to 2a2108c (the remaining windows failures are pre-existing from #22)

@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2021

Codecov Report

Merging #27 (9bc1306) into master (43d8d30) will increase coverage by 0.07%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
+ Coverage   95.83%   95.90%   +0.07%     
==========================================
  Files           2        2              
  Lines         168      171       +3     
==========================================
+ Hits          161      164       +3     
  Misses          7        7              
Impacted Files Coverage Δ
pgsu/__init__.py 95.59% <88.88%> (+0.08%) ⬆️
pgsu/cli.py 100.00% <100.00%> (ø)

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 43d8d30...9bc1306. Read the comment docs.

@chrisjsewell chrisjsewell requested a review from ltalirz August 30, 2021 06:26
@chrisjsewell
Copy link
Member Author

chrisjsewell commented Aug 30, 2021

should probably drop ububtu-1604 now, as it looks like the containers are no longer available,
and python 3.5: done

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks @chrisjsewell !

so the issue is just that the connection needs to be closed?
from looking at the code it's not so easy to see what the actual difference is

@@ -97,9 +91,9 @@ jobs:
run: |
sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list
sudo apt update
sudo apt install postgresql-12
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason to downgrade?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeh for some reason 1804 apt only has v10 available (I checked locally in a docker container)

@chrisjsewell
Copy link
Member Author

chrisjsewell commented Aug 30, 2021

so the issue is just that the connection needs to be closed?

no its that you don't use a contextmanager for the connection, so that psycopg2 does not start a transaction (which only happens in v2.9). you use a try/finally instead

Comment on lines -254 to +256
with psycopg2.connect(**dsn) as conn:
try:
conn = psycopg2.connect(**dsn)
Copy link
Member Author

Choose a reason for hiding this comment

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

the actual fix is here

Copy link
Member

@ltalirz ltalirz Aug 30, 2021

Choose a reason for hiding this comment

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

Thanks!

could you please add a comment to that effect in the code?

i.e. "don't use a context manager so that psycopg2 does not start a transaction" ?

There is no variable one can pass to the context manager to tell it not to do this, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not according to the issue I linked to from psycopg. As it says there, the contextmanager was not actually doing anything before (in v2.8) anyway

@chrisjsewell chrisjsewell merged commit 619d3aa into master Aug 30, 2021
@chrisjsewell chrisjsewell deleted the fix-psycopg branch August 30, 2021 08:13
chrisjsewell added a commit to aiidateam/aiida-core that referenced this pull request Aug 30, 2021
sphuber pushed a commit to aiidateam/aiida-core that referenced this pull request Feb 16, 2022
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.

3 participants