-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add ensure-compiled endpoint to control plane server #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 11-30-feat_core_add_ensure_flow_compiled_function
Are you sure you want to change the base?
Conversation
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
View your CI Pipeline Execution ↗ for commit 6ed062f
☁️ Nx Cloud last updated this comment at |
| const [result] = await options.sql` | ||
| SELECT pgflow.ensure_flow_compiled( | ||
| ${flowSlug}, | ||
| ${JSON.stringify(shape)}::jsonb, | ||
| ${mode} | ||
| ) as result | ||
| `; | ||
|
|
||
| const response = result.result as EnsureCompiledResponse; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Accessing result.result on line 299 will throw a runtime error if the SQL query returns an empty array. The array destructuring const [result] = await options.sql... will set result to undefined if the array is empty, causing result.result to throw TypeError: Cannot read property 'result' of undefined.
While this is caught by the try-catch block and returns a 500 error, it produces a misleading error message. The code should explicitly check if a result was returned:
const results = await options.sql`
SELECT pgflow.ensure_flow_compiled(
${flowSlug},
${JSON.stringify(shape)}::jsonb,
${mode}
) as result
`;
if (!results || results.length === 0 || !results[0]?.result) {
return jsonResponse(
{
error: 'Database Error',
message: 'No result returned from ensure_flow_compiled function',
},
500
);
}
const response = results[0].result as EnsureCompiledResponse;| const [result] = await options.sql` | |
| SELECT pgflow.ensure_flow_compiled( | |
| ${flowSlug}, | |
| ${JSON.stringify(shape)}::jsonb, | |
| ${mode} | |
| ) as result | |
| `; | |
| const response = result.result as EnsureCompiledResponse; | |
| const results = await options.sql` | |
| SELECT pgflow.ensure_flow_compiled( | |
| ${flowSlug}, | |
| ${JSON.stringify(shape)}::jsonb, | |
| ${mode} | |
| ) as result | |
| `; | |
| if (!results || results.length === 0 || !results[0]?.result) { | |
| return jsonResponse( | |
| { | |
| error: 'Database Error', | |
| message: 'No result returned from ensure_flow_compiled function', | |
| }, | |
| 500 | |
| ); | |
| } | |
| const response = results[0].result as EnsureCompiledResponse; | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
37bddc8 to
6ed062f
Compare
cbfdb88 to
4cd34c0
Compare
🔍 Preview Deployment: Website✅ Deployment successful! 🔗 Preview URL: https://pr-467.pgflow.pages.dev 📝 Details:
_Last updated: _ |

Add ensure-compiled endpoint to edge worker control plane
This PR adds a new endpoint to the edge worker control plane API:
/flows/:slug/ensure-compiled. This endpoint allows clients to verify that a flow's compiled SQL matches its expected shape, or to recompile it if needed.Key features:
The endpoint returns different status codes based on the result:
Comprehensive tests have been added to verify all functionality and edge cases.