Skip to content

Can't use GCP Cloud SQL connection string with native PostgresSettings #32

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

Closed
rodrigoalmeida94 opened this issue Jul 11, 2022 · 2 comments
Labels
question Further information is requested

Comments

@rodrigoalmeida94
Copy link

rodrigoalmeida94 commented Jul 11, 2022

When using GCP database instances with Cloud Run functions, the connection string of the database includes unix sockets, i.e.:

postgresql://cerulean-cloud-test-database:APASSWORD@/SOMEDB?host=/cloudsql/SOME-PROJECT:europe-west1:SOME-INSTANCE-af6e417

Passing this as DATABASE_URL returns a validation error coming from Pydantic.PostgresDsn -

return pydantic.PostgresDsn.build(
.
This has been discussed upstream and more recently here, and looks like this won't be addressed any time soon. Since MagicStack/asyncpg#419 AsyncPg supports these types of connection string.

The way I got around this now is defining my own PostgresSettings class, removing the pydantic validation all together. This is fine but I'm wondering if it could make sense to add an extra env var like TIFEATURES_CLOUDSQL which we could set to True, and then that would bypass the pydantic validation?

Thanks!

@rodrigoalmeida94 rodrigoalmeida94 added the question Further information is requested label Jul 11, 2022
@vincentsarago
Copy link
Member

Thanks for opening the issue @rodrigoalmeida94

This is fine but I'm wondering if it could make sense to add an extra env var like TIFEATURES_CLOUDSQL which we could set to True, and then that would bypass the pydantic validation?

I kinda don't really like adding something specific for Cloud provider use case, and would prefer if we can push the fix upstream or do like you do: customize your own application!

@rodrigoalmeida94
Copy link
Author

Perfect, makes sense to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants