{"record":{"id":"6b693f1786bec3b4","repo":"apache/beam","slug":"database-host-cannot-be-empty","errorCode":null,"errorMessage":"Database host cannot be empty","messagePattern":"Database host cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql.py","lineNumber":196,"sourceCode":"        host: Hostname or IP address of the database server.\n        port: Port number for the database connection.\n        user: Username for authentication.\n        password: Password for authentication.\n        db_id: Database identifier/name.\n        connect_kwargs: Additional keyword arguments for the client connect\n          method. Enables forward compatibility.\n    \"\"\"\n  db_adapter: DatabaseTypeAdapter\n  host: str\n  port: int\n  user: str = field(default_factory=str)\n  password: str = field(default_factory=str)\n  db_id: str = field(default_factory=str)\n  connect_kwargs: dict[str, Any] = field(default_factory=dict)\n\n  def __post_init__(self):\n    if not self.host:\n      raise ValueError(\"Database host cannot be empty\")\n\n  def get_connector_handler(self) -> Callable[[], DBAPIConnection]:\n    \"\"\"Returns a function that creates a new database connection.\n\n      The returned connector function creates database connections that should\n      be properly closed by the caller when no longer needed.\n      \"\"\"\n    if self.db_adapter == DatabaseTypeAdapter.POSTGRESQL:\n      return lambda: pg8000.connect(\n          host=self.host, port=self.port, database=self.db_id, user=self.user,\n          password=self.password, **self.connect_kwargs)\n    elif self.db_adapter == DatabaseTypeAdapter.MYSQL:\n      return lambda: pymysql.connect(\n          host=self.host, port=self.port, database=self.db_id, user=self.user,\n          password=self.password, **self.connect_kwargs)\n    elif self.db_adapter == DatabaseTypeAdapter.SQLSERVER:\n      return lambda: pytds.connect(\n          dsn=self.host, port=self.port, database=self.db_id, user=self.user,","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql.py#L178-L214","documentation":"The database-specific connection config dataclass (host/user/password/db_id based) validates in __post_init__ that host is non-empty. With the Cloud SQL Python Connector, host carries the instance connection URI, so an empty host makes connection impossible.","triggerScenarios":"Constructing a config such as QueryCloudSQLConnectionConfig or TableCloudSQLConnectionConfig without host, or with host=\"\" or None.","commonSituations":"Assuming a localhost default exists; options/env not plumbed through to the worker; editing a shared config template and dropping the host field.","solutions":["Set host to the instance connection URI ('project:region:instance') when using the Cloud SQL connector.","Verify the config kwargs match the dataclass field names exactly.","Validate required fields before constructing the config."],"exampleFix":"# before\nconfig = QueryCloudSQLConnectionConfig(host=\"\", db_adapter=DatabaseTypeAdapter.POSTGRESQL, ...)\n# after\nconfig = QueryCloudSQLConnectionConfig(host=\"my-project:us-central1:my-instance\", db_adapter=DatabaseTypeAdapter.POSTGRESQL, ...)","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["python","configuration","cloudsql","apache-beam"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}