cloud-sql-python-connector
cloud-sql-python-connector copied to clipboard
Validate driver matches database type
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