cloud-sql-python-connector icon indicating copy to clipboard operation
cloud-sql-python-connector copied to clipboard

Validate driver matches database type

Open jackwotherspoon opened this issue 1 year ago • 0 comments

The behavior where someone passes a valid instance connection name for a Cloud SQL instance but for the wrong driver is slightly ambiguous currently. (ex. instance connection name for a Cloud SQL Postgres instance but with pymysql driver)

We should make an enum mapping drivers to database type and verify that the driver being used is correct before attempting a connection. This way we can throw a helpful error message to users pointing at the wrong instance.

We are already returning the database version as part of the metadata request so this should be pretty straightforward.

https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/blob/25a740a5db88088082820b6ae72f4b4a2a52dd2d/google/cloud/sql/connector/refresh_utils.py#L110-L114

jackwotherspoon avatar Feb 01 '24 19:02 jackwotherspoon