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

database_exists throws error if username and db name are different for postgresql #472

Open
AramayisO opened this issue Sep 2, 2020 · 6 comments

Comments

@AramayisO
Copy link

In my test environment, I have a user named "user" that only has access to a database named "test". If I run
database_exists("postgresql://user:password@localhost/test"), I get the following error: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: database "user" does not exist.

It looks like this behavior results from this line of code introduced in 5d99747

database, url.database = url.database, None

With url.database set to None, the code assumes we are connecting to a database with the same name as the username.

@fmigneault
Copy link
Contributor

I'm also seeing this problem.
I can confirm that reapplying the url.database name to the original value (ie: test in provided example) correctly finds the expected database, and with None enforced here, it looks for user database.

@fmigneault
Copy link
Contributor

duplicate of #462
fixed by #463

@dpb-bah
Copy link

dpb-bah commented Sep 29, 2020

Can confirm this is an issue. Had to revert to 0.36.7.

@redspart
Copy link

redspart commented Nov 19, 2020

I see this observe this behavior:

  • Python3.6.9 running version 0.36.8 gets the error above
  • Python3.6.9 running version 0.36.7 does not get this error
  • Python3.6.12 running version 0.36.8 does not get this error

@sfc-gh-pkommini
Copy link

sfc-gh-pkommini commented Dec 17, 2020

I see this error on python 3.8.6 and 0.36.8 but don't see it on 0.36.7. Although, I think it has less to do with the python version and more to do with the sqlalchemy-utils library version

@tanj
Copy link

tanj commented Dec 22, 2020

This commit 5d99747 needs to be reversed.

PostgreSQL needs to connect explicitly to the postgres database if connecting with a user other than postgres to be able to query pg_database

Current test cases only connect with postgres user, so seem to pass be allow for this failure.

sandalwoodbox added a commit to FanvidDB/fanviddb-server that referenced this issue Mar 15, 2021
sirex added a commit to atviriduomenys/spinta that referenced this issue Feb 28, 2022
Python 3.8 is still used in production, but in development env, it is
time to upgrade to 3.9.

There was issue with sqlalchemy-utils, downgrading it fixed the issue:

kvesteri/sqlalchemy-utils#472
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

No branches or pull requests

6 participants