{"record":{"id":"a4717ec6769d195c","repo":"cocoindex-io/cocoindex","slug":"to-table-must-be-specified-for-polymorphic-relatio","errorCode":null,"errorMessage":"to_table must be specified for polymorphic relations (possible tables: {self._to_table_names})","messagePattern":"to_table must be specified for polymorphic relations \\(possible tables: (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/surrealdb/_target.py","lineNumber":1217,"sourceCode":"        \"\"\"Declare a relation record.\"\"\"\n        # Resolve from_table_name\n        if from_table is not None:\n            from_table_name = from_table.table_name\n        elif self._default_from_table is not None:\n            from_table_name = self._default_from_table\n        else:\n            raise ValueError(\n                \"from_table must be specified for polymorphic relations \"\n                f\"(possible tables: {self._from_table_names})\"\n            )\n\n        # Resolve to_table_name\n        if to_table is not None:\n            to_table_name = to_table.table_name\n        elif self._default_to_table is not None:\n            to_table_name = self._default_to_table\n        else:\n            raise ValueError(\n                \"to_table must be specified for polymorphic relations \"\n                f\"(possible tables: {self._to_table_names})\"\n            )\n\n        # Build the value dict from the record (exclude 'id' — it's the key, not content)\n        if record is not None:\n            if self._table_schema is not None:\n                row_dict: dict[str, Any] = {}\n                for col_name, col in self._table_schema.columns.items():\n                    if col_name == \"id\":\n                        continue\n                    if isinstance(record, dict):\n                        value = record.get(col_name)\n                    else:\n                        value = getattr(record, col_name)\n                    if value is not None and col.encoder is not None:\n                        value = col.encoder(value)\n                    row_dict[col_name] = value","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/surrealdb/_target.py#L1199-L1235","documentation":"Mirror of the from-table case: for a polymorphic relation target there is no single default to-table, so `declare_relation` raises ValueError listing the candidate destination tables when `to_table` is omitted.","triggerScenarios":"Calling `declare_relation(...)` with a `from_table` (or relying on the default from-table) but without `to_table=...` when the target has multiple possible to-tables.","commonSituations":"Edges that may point at several node tables (User→Post, User→Comment); assuming the endpoint is inferred from the record's contents.","solutions":["Pass `to_table=<TableTarget>` chosen from the `(possible tables: ...)` list in the error message.","If relations always target one table, declare the relation target with a single to-table so the default applies.","Ensure the record object doesn't carry the table implicitly — the API requires it explicitly."],"exampleFix":"// before\nawait rel_target.declare_relation(record=follow, from_table=user_table)\n// after\nawait rel_target.declare_relation(record=follow, from_table=user_table, to_table=user_table)","handlingStrategy":"validation","validationCode":"if to_table is None and rel_target.default_to_table is None:\n    raise ValueError(\"declare_relation requires to_table for polymorphic relation targets\")","typeGuard":"def can_omit_to_table(rel_target) -> bool:\n    return getattr(rel_target, \"_default_to_table\", None) is not None","tryCatchPattern":"try:\n    await rel_target.declare_relation(record=rec, from_table=src)\nexcept ValueError as e:\n    if \"to_table must be specified\" in str(e):\n        await rel_target.declare_relation(record=rec, from_table=src, to_table=dst)\n    else:\n        raise","preventionTips":["Always specify to_table explicitly in multi-table schemas.","Use the error's possible-tables list to choose a valid destination.","Prefer single-endpoint relation targets when your graph has fixed edge directions."],"tags":["python","graph","surrealdb","config"],"backgroundTag":"missing-required-argument","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}