{"record":{"id":"154e8c90805a831d","repo":"iflytek/astron-agent","slug":"pg-sql-request-error","errorCode":"PG_SQL_REQUEST_ERROR","errorMessage":"err code {background_json.get('code')}, reason {background_json.get('message')}, sid {background_json.get('sid')}","messagePattern":"err code (.+?), reason (.+?), sid (.+?)","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/pgsql/pgsql_client.py","lineNumber":128,"sourceCode":"                        # Log execution time and response for monitoring\n                        await request_span.add_info_events_async(\n                            {\"cost_time\": f\"{(time.time() - start_time) * 1000}\"}\n                        )\n                        await request_span.add_info_events_async(\n                            {\n                                \"response\": json.dumps(\n                                    background_json, ensure_ascii=False\n                                )\n                            }\n                        )\n                        # Check for service-level errors in response\n                        if background_json.get(\"code\") != 0:\n                            msg = (\n                                f\"err code {background_json.get('code')}, \"\n                                f\"reason {background_json.get('message')}, sid {background_json.get('sid')}\"\n                            )\n                            request_span.add_error_event(msg)\n                            raise CustomException(\n                                err_code=CodeEnum.PG_SQL_REQUEST_ERROR,\n                                err_msg=f\"{msg}\",\n                            )\n                        return background_json\n            except CustomException as e:\n                # Re-raise custom exceptions as-is\n                raise e\n            except Exception as e:\n                # Handle unexpected errors during request execution\n                err = str(e)\n                request_span.add_error_event(err)\n                raise CustomException(\n                    err_code=CodeEnum.PG_SQL_REQUEST_ERROR,\n                    err_msg=f\"Database POST request failed: {err}\",\n                    cause_error=f\"Database POST request failed: {err}\",\n                ) from e\n\n    def payload(self) -> Dict[str, Any]:","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/pgsql/pgsql_client.py#L110-L146","documentation":"The PostgreSQL backend service responded with a JSON body whose `code` field is non-zero, indicating the backend rejected or failed the request. `exec_dml` wraps the backend's `code`, `message` and `sid` into a PG_SQL_REQUEST_ERROR so callers get the upstream reason and trace id.","triggerScenarios":"Calling `exec_dml` where the HTTP call succeeds (200) but the response body has `code != 0`, e.g. backend SQL execution failed, invalid session (sid), or backend-internal error.","commonSituations":"Backend service returning business errors like SQL syntax rejection, permission denied on the target table, backend timeout, or backend service degraded; debugging via the `sid` in the message against backend logs.","solutions":["Read the `reason`/`sid` in the message and look up the sid in the PostgreSQL backend service logs to find the root cause.","Validate the generated SQL and parameters before calling exec_dml (use the node's generate_dml to inspect the compiled statement).","Check backend service health and its database connectivity (credentials, network) — most non-zero codes are backend-side failures.","Retry only for transient backend errors after confirming the request payload is valid."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = client.exec_dml(...)\nexcept CustomException as e:\n    if \"err code\" in str(e):\n        sid = extract_sid(str(e))  # parse sid for backend log lookup\n        log.error(\"PGSQL backend rejected request\", sid=sid, detail=str(e))\n    raise","preventionTips":["Validate SQL and parameters client-side before sending","Monitor backend service health and alerts","Log the sid so backend failures can be traced quickly"],"tags":["postgresql","upstream","request-failed","api"],"backgroundTag":"upstream-api-error","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"}