You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use asyncpg to connect to Google Cloud SQL together with [databases](https://github.com/encode/databases/), alembic and sometimes sqlalchemy. It's quite convenient to have one database url that can be used in different cases.
But there's one problem as the Cloud SQL host is in the format /cloudsql/<project>:<region>:<db_instance>.
Would it be possible to consider adding the support for such a case?
Naive solution seems to be to use rpartition there, so the url
'postgresql://USER:PWD@/DB?host=/cloudsql/::<db_instance>:5432'
can be used, but I can investigate this one more thorough if seems like a reasonable case.
but I have to make a workaround to pass host additionally as a kwarg, so asyncpg.connection. connect receives dsn and host as above as host from the kwargs takes precedence.
I'm trying to figure the state of this issue and it's not clear to me. Are we able to pass the CloudSQL /cloudsql/<project>:<region>:<db_instance> format? I tried to urlencode but I'm getting the same issue that actual string is not kep as it should.
Looking through the code a bit more. It seems the logic is to assume Host:Port from the get go (and call _parse_hostlist). Maybe a check before calling that function for the host starting with a /? Or change its name and make the check from within?
Activity
elprans commentedon Apr 3, 2019
Can you show the URL you are using with sqlalchemy?
gvbgduh commentedon Apr 7, 2019
The url is
so
hostisbut I have to make a workaround to pass
hostadditionally as a kwarg, soasyncpg.connection. connectreceivesdsnandhostas above ashostfrom the kwargs takes precedence.gvbgduh commentedon Apr 7, 2019
It could be either
the result is similar.
but it's parsed as
leosussan commentedon Jun 6, 2019
Bumping this - am having the exact same issue.
ioistired commentedon Jun 21, 2019
Try URL encoding the colons?
Lawouach commentedon Aug 5, 2019
Hi there,
I'm trying to figure the state of this issue and it's not clear to me. Are we able to pass the CloudSQL
/cloudsql/<project>:<region>:<db_instance>format? I tried to urlencode but I'm getting the same issue that actual string is not kep as it should.Lawouach commentedon Aug 6, 2019
Looking through the code a bit more. It seems the logic is to assume Host:Port from the get go (and call _parse_hostlist). Maybe a check before calling that function for the host starting with a
/? Or change its name and make the check from within?Do not look for a port in a Unix socket domain path
Do not look for a port in a Unix socket domain path
Do not look for a port in a Unix socket domain path
Do not look for a port in a Unix socket domain path
maxzheng commentedon Apr 11, 2020
This is working now in the latest version (with #470), maybe someone can close this ticket to avoid confusion?
gvbgduh commentedon Apr 11, 2020
awesome news @maxzheng!
JeffryCA commentedon Nov 5, 2021
Hi @maxzheng Can you tell me in detail how you made it work? I have been trying:
david-dest01 commentedon Nov 5, 2022
Anyone actually answer this for you? I'm not able to get this going and there doesn't seem to be a clear example/overview of expected format.
geminixiang commentedon Apr 26, 2023
Cloud run can't connect to Cloud SQL, have someone has correct url format for Cloud SQL
geminixiang commentedon Apr 27, 2023
this is correct url format
and cloud run must be configured to specify which instance you wanna connect to
ofer-pd commentedon Oct 11, 2024
FYI - When I tried setting the scheme to "postgresql+asyncpg" as recommended in the previous comment, I got the following error:
Using asyncpg v0.29.0.