{"record":{"id":"d6308c2d1b48c57e","repo":"iflytek/astron-agent","slug":"pg-sql-param-error","errorCode":"PG_SQL_PARAM_ERROR","errorMessage":"Invalid {field_type}: {key} is a reserved keyword in database","messagePattern":"Invalid (.+?): (.+?) is a reserved keyword in database","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/configs/app_config.py","lineNumber":165,"sourceCode":"    PostgreSQL configuration model.\n\n    This model represents the PostgreSQL configuration with its keyword list.\n    \"\"\"\n\n    model_config = {\"env_prefix\": \"\", \"case_sensitive\": False}\n    keyword_list: List[str] = Field(default=DB_SQL_INVALID_KEY, alias=\"KEYWORD_LIST\")\n\n    def is_valid(self, key: str, field_type: str) -> None:\n        \"\"\"\n        Validate if the key is valid.\n\n        :param key: The key to validate\n        :param field_type: The type of the field\n        :raises CustomException: If the key is not valid\n        \"\"\"\n        key_lower = key.lower()\n        if key_lower in DB_SQL_INVALID_KEY:\n            raise CustomException(\n                err_code=CodeEnum.PG_SQL_PARAM_ERROR,\n                err_msg=f\"Invalid {field_type}: {key} is a reserved keyword in database\",\n                cause_error=f\"Invalid {field_type}: {key} is a reserved keyword in database\",\n            )\n\n\nclass KafkaConfig(BaseSettings):\n    \"\"\"\n    Kafka configuration model.\n\n    This model represents the Kafka configuration with its various settings.\n    Attributes:\n        kafka_servers: Kafka broker addresses, comma-separated\n        kafka_protocol: Security protocol (PLAINTEXT, SASL_PLAINTEXT, SSL, SASL_SSL)\n        kafka_mechanism: SASL mechanism (PLAIN, SCRAM-SHA-256, SCRAM-SHA-512)\n        kafka_username: SASL username\n        kafka_password: SASL password\n        kafka_enable: Whether Kafka is enabled (0/1 or true/false)","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/configs/app_config.py#L147-L183","documentation":"FileConfig.is_valid (key validation helper) raises CustomException PG_SQL_PARAM_ERROR when a field or column key matches an entry in DB_SQL_INVALID_KEY, i.e. a PostgreSQL reserved keyword. Such keys would break or risk injection when used in generated SQL identifiers for knowledge-base fields.","triggerScenarios":"Creating/updating a dataset or table field named 'order', 'select', 'group', 'user', etc.; importing a schema (CSV headers, JSON keys) whose column name is a SQL reserved word; case-insensitive match caught via key.lower().","commonSituations":"CSV header 'order' imported as a knowledge base field; user names a metadata field 'desc'; upstream rename introduces a reserved word into the schema sync.","solutions":["Rename the field to a non-reserved identifier, e.g. 'order' -> 'order_name' or 'order_value'","Prefix/suffix reserved keys automatically before persisting (e.g. wrap in quotes or add 'f_' prefix)","Validate user-provided field names against DB_SQL_INVALID_KEY at the API boundary and reject early with a clear message","Consult the PostgreSQL reserved keyword list when designing field names"],"exampleFix":"// before\nfield_key = \"order\"       # reserved keyword -> PG_SQL_PARAM_ERROR\n// after\nfield_key = \"order_value\"","handlingStrategy":"validation","validationCode":"from workflow.configs.app_config import DB_SQL_INVALID_KEY\nif key.lower() in DB_SQL_INVALID_KEY:\n    raise FieldNameRejected(f\"{key!r} is a reserved SQL keyword\")","typeGuard":null,"tryCatchPattern":"try:\n    file_config.validate_key(key, field_type=\"field\")\nexcept CustomException as e:\n    if e.err_code == CodeEnum.PG_SQL_PARAM_ERROR:\n        return field_error(suggest=f\"{key}_value\")\n    raise","preventionTips":["Sanitize/transform field names at the API boundary before persistence","Avoid PostgreSQL reserved words when naming CSV headers or metadata keys","Auto-prefix reserved matches (e.g. f_) if renaming is not acceptable","Share the reserved-keyword list with schema-import tooling"],"tags":["postgresql","naming","validation","sql-injection"],"backgroundTag":"invalid-identifier-format","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}