{"record":{"id":"09eb3ee1dff4ce35","repo":"cocoindex-io/cocoindex","slug":"primary-key-column-pk-not-found-in-columns-l-09eb3e","errorCode":null,"errorMessage":"Primary key column '{pk}' not found in columns: {list(self.columns.keys())}","messagePattern":"Primary key column '(.+?)' not found in columns: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/snowflake/_target.py","lineNumber":120,"sourceCode":"\n    columns: dict[str, ColumnDef]\n    primary_key: list[str]\n    row_type: type[RowT] | None\n\n    def __init__(\n        self,\n        columns: dict[str, ColumnDef],\n        primary_key: list[str],\n        *,\n        row_type: type[RowT] | None = None,\n    ) -> None:\n        self.columns = columns\n        self.primary_key = primary_key\n        self.row_type = row_type\n\n        for pk in self.primary_key:\n            if pk not in self.columns:\n                raise ValueError(\n                    f\"Primary key column '{pk}' not found in columns: {list(self.columns.keys())}\"\n                )\n\n    @classmethod\n    async def from_class(\n        cls,\n        record_type: type[RowT],\n        primary_key: list[str],\n        *,\n        column_overrides: dict[str, SnowflakeType] | None = None,\n    ) -> \"TableSchema[RowT]\":\n        \"\"\"\n        Create a TableSchema from a record type.\n\n        Args:\n            record_type: A dataclass, NamedTuple, or Pydantic model.\n            primary_key: List of column names that form the primary key.\n            column_overrides: Optional per-column SnowflakeType overrides.","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/snowflake/_target.py#L102-L138","documentation":"The Snowflake target connector requires every primary key column to exist in the declared columns dict. In __init__ of the target (table) definition, each name in primary_key is checked against columns; a missing name raises this ValueError listing the columns that DO exist, so the mismatch is immediately visible.","triggerScenarios":"Constructing the Snowflake table target with a primary_key list containing a column name absent from `columns` — e.g. a typo, a case mismatch ('ID' vs 'id'), or a PK column defined only in the external table but not in the declared row type.","commonSituations":"Renaming a column in the schema but not in primary_key; Snowflake identifier case (unquoted identifiers are upper-cased by Snowflake) causing 'id' vs 'ID' mismatch; PK config copied from another table's definition.","solutions":["Compare the message's column list with your primary_key and fix the typo/case so the PK name matches a declared column exactly.","Add the missing column to the columns/row_type definition if it should be part of the schema.","Remove the stale PK entry if that column is no longer part of the key.","Remember Snowflake stores unquoted identifiers uppercase — make the declared name match how the column is actually defined."],"exampleFix":"// before\nTableTarget(columns={\"id\": IntegerType(), \"name\": TextType()}, primary_key=[\"doc_id\"])\n// after\nTableTarget(columns={\"id\": IntegerType(), \"name\": TextType()}, primary_key=[\"id\"])","handlingStrategy":"validation","validationCode":"missing = set(primary_key) - set(columns)\nassert not missing, f\"PK columns not declared: {missing}\"","typeGuard":"all(pk in columns for pk in primary_key)","tryCatchPattern":"try:\n    target = SnowflakeTableTarget(columns=cols, primary_key=pk)\nexcept ValueError as e:\n    raise SchemaError(f\"snowflake PK mismatch: {e}\") from None","preventionTips":["Keep primary_key as a strict subset of columns and enforce it where the schema is defined.","Watch Snowflake identifier casing: unquoted identifiers are stored uppercase — compare case-insensitively or quote consistently.","Update primary_key in the same change as any column rename.","Fail fast on schema load: validate PK ⊆ columns before constructing the target."],"tags":["snowflake","schema","primary-key"],"backgroundTag":"resource-not-found","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}