apache/beam · error · ValueError

Unsupported database adapter

Error message

Unsupported database adapter: {self.db_adapter}

What it means

get_connector_handler builds a lambda that opens DBAPI connections using the driver matching db_adapter (pg8000 for PostgreSQL, pymysql for MySQL, pytds for SQL Server). If db_adapter is none of the supported DatabaseTypeAdapter values, the handler raises ValueError rather than guessing a driver.

Solutions

  1. Use DatabaseTypeAdapter.POSTGRESQL, MYSQL, or SQLSERVER instead of a raw string.
  2. Check the DatabaseTypeAdapter enum for the full set of supported adapters.
  3. For an unsupported database, use a different enrichment handler or extend get_connector_handler.

Example fix

# before
config = QueryCloudSQLConnectionConfig(db_adapter="postgres", host=uri, ...)
# after
from apache_beam.transforms.enrichment_handlers.cloudsql import DatabaseTypeAdapter
config = QueryCloudSQLConnectionConfig(db_adapter=DatabaseTypeAdapter.POSTGRESQL, host=uri, ...)
Defensive patterns

Strategy: validation

When it happens

Trigger: Passing db_adapter as a raw string like 'postgres' instead of a DatabaseTypeAdapter enum member, or an adapter type not covered by the if/elif chain (e.g. Oracle).

Common situations: Passing a plain string instead of the enum; using a database flavor the handler does not support; refactors that renamed enum members.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/3524ec9ce6c4d5bd. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql.py:217

    """Returns a function that creates a new database connection.

      The returned connector function creates database connections that should
      be properly closed by the caller when no longer needed.
      """
    if self.db_adapter == DatabaseTypeAdapter.POSTGRESQL:
      return lambda: pg8000.connect(
          host=self.host, port=self.port, database=self.db_id, user=self.user,
          password=self.password, **self.connect_kwargs)
    elif self.db_adapter == DatabaseTypeAdapter.MYSQL:
      return lambda: pymysql.connect(
          host=self.host, port=self.port, database=self.db_id, user=self.user,
          password=self.password, **self.connect_kwargs)
    elif self.db_adapter == DatabaseTypeAdapter.SQLSERVER:
      return lambda: pytds.connect(
          dsn=self.host, port=self.port, database=self.db_id, user=self.user,
          password=self.password, **self.connect_kwargs)
    else:
      raise ValueError(f"Unsupported database adapter: {self.db_adapter}")

  def get_db_url(self) -> str:
    return self.db_adapter.to_sqlalchemy_dialect() + "://"


QueryConfig = Union[CustomQueryConfig,
                    TableFieldsQueryConfig,
                    TableFunctionQueryConfig]


class CloudSQLEnrichmentHandler(EnrichmentSourceHandler[beam.Row, beam.Row]):
  """Enrichment handler for Cloud SQL databases.

  This handler is designed to work with the
  :class:`apache_beam.transforms.enrichment.Enrichment` transform.

  To use this handler, you need to provide one of the following query configs:
    * CustomQueryConfig - For providing a custom query function

View on GitHub (pinned to 12126d8942)