Canner / WrenAI

🚀 An open-source SQL AI (Text-to-SQL) Agent that empowers data, product teams to chat with their data. 🤘
https://getwren.ai/oss
GNU Affero General Public License v3.0
2.04k stars 211 forks source link

Fix(wren-ui): fix previewSql mutation for doing dry run #406

Closed onlyjackfrost closed 5 months ago

onlyjackfrost commented 5 months ago

Example GraphQL response when failed

{
    "errors": [
        {
            "locations": [
                {
                    "line": 1,
                    "column": 51
                }
            ],
            "path": [
                "previewSql"
            ],
            "message": "Exception: <class 'psycopg2.errors.UndefinedTable'>, message: relation \"public_order\" does not exist\nLINE 1: ...hic5g3ffz553y AS SELECT tmp.* FROM (SELECT * FROM public_ord...\n                                                             ^\n",
            "extensions": {
                "code": "DRY_RUN_ERROR",
                "message": "Exception: <class 'psycopg2.errors.UndefinedTable'>, message: relation \"public_order\" does not exist\nLINE 1: ...hic5g3ffz553y AS SELECT tmp.* FROM (SELECT * FROM public_ord...\n                                                             ^\n",
                "shortMessage": "Dry run sql statement error",
                "stacktrace": [
                    "GraphQLError: Exception: <class 'psycopg2.errors.UndefinedTable'>, message: relation \"public_order\" does not exist",
                    "LINE 1: ...hic5g3ffz553y AS SELECT tmp.* FROM (SELECT * FROM public_ord...",
                    "                                                             ^",
                    "",
                    "    at Module.create (webpack-internal:///(api)/./src/apollo/server/utils/error.ts:86:17)",
                    "    at IbisAdaptor.dryRun (webpack-internal:///(api)/./src/apollo/server/adaptors/ibisAdaptor.ts:77:68)",
                    "    at runMicrotasks (<anonymous>)",
                    "    at processTicksAndRejections (node:internal/process/task_queues:96:5)",
                    "    at async QueryService.preview (webpack-internal:///(api)/./src/apollo/server/services/queryService.ts:52:17)",
                    "    at async ModelResolver.previewSql (webpack-internal:///(api)/./src/apollo/server/resolvers/modelResolver.ts:541:28)"
                ]
            }
        }
    ],
    "data": null
}