step.db_query_cached: add mode field for single/list result support#238
step.db_query_cached: add mode field for single/list result support#238
Conversation
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
|
@copilot Address the merge conflicts on the branch |
…e support Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Resolved in 31e339a. The branch now includes
|
There was a problem hiding this comment.
Pull request overview
Adds full mode support to step.db_query_cached so cached queries can return either a single-row envelope (row/found) or multi-row results (rows/count), aligning its behavior with step.db_query.
Changes:
- Add
mode(single/list) parsing + validation tostep.db_query_cached, and update its output shape to matchstep.db_query. - Update
step.db_query_cachedmodule schema to includemodeand to describe the new output contract. - Update and expand tests to cover list-mode behavior, cache hit/miss, and the new single-mode envelope output.
Reviewed changes
Copilot reviewed 5 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
module/pipeline_step_db_query_cached.go |
Adds mode handling and returns row/found (single) or rows/count (list). |
module/pipeline_step_db_query_cached_test.go |
Updates existing assertions for the new output shape and adds list-mode coverage. |
schema/module_schema.go |
Documents mode for step.db_query_cached and updates output description. |
schema/schema.go |
Formatting-only alignment in schema generation map literal. |
schema/snippets_export.go |
Formatting-only alignment in XML struct tags. |
module/pipeline_step_db_query_test.go |
Formatting-only alignment. |
module/pipeline_step_token_revoke_test.go |
Removes trailing blank line. |
module/pipeline_step_sandbox_exec.go |
Formatting-only alignment in struct literal. |
module/kafka_broker.go |
Import/field alignment formatting. |
module/http_server.go |
Formatting-only alignment in struct tags. |
module/cache_redis.go |
Formatting-only alignment / comment spacing. |
| output := make(map[string]any) | ||
| if s.mode == "single" { | ||
| if len(results) > 0 { | ||
| output["row"] = results[0] | ||
| output["found"] = true | ||
| } else { | ||
| output["row"] = map[string]any{} | ||
| output["found"] = false | ||
| } | ||
| } else { | ||
| if results == nil { | ||
| results = []map[string]any{} | ||
| } | ||
| output["rows"] = results | ||
| output["count"] = len(results) | ||
| } |
There was a problem hiding this comment.
Now that results are nested structures (row is a map and rows is a slice of maps), caching via copyMap (a shallow copy) will return shared references to the cached nested data. If any downstream code mutates row/rows (or if future steps do), it can corrupt the cache and create cross-goroutine data races. Consider deep-copying nested maps/slices when storing to or returning from the cache.
|
@copilot apply changes based on the comments in this thread |
…r allowlist, backward compat mode Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Applied all three review items in 2efb1d1:
|
step.db_query_cachedwas missingmodesupport entirely — it only returned a flat map of the first row's columns, making it inconsistent withstep.db_queryand unable to cache list query results.Changes
module/pipeline_step_db_query_cached.gomodefield ("single"|"list"); invalid values are rejected at factory timemodepreserves the original legacy flat column map output (backward compatible)mode: single→{ "row": {...}, "found": bool, "cache_hit": bool }(consistent withstep.db_query)mode: list→{ "rows": [...], "count": N, "cache_hit": bool }(new)copyMapwithdeepCopyMapthat recursively copies nestedmap[string]anyand[]map[string]any, preventing cache corruption and cross-goroutine data racesallow_dynamic_sqlsupport: when enabled, template expressions in the query are resolved at runtime and validated as safe SQL identifiers before executionmodule/pipeline_step_db_dynamic.go: AddedresolveDynamicSQLandvalidateSQLIdentifierhelpers; SQL identifier allowlist restricted to ASCII letters, digits, and underscores only (hyphens removed as they are not valid unquoted SQL identifiers)schema/module_schema.go: Addedmodeselect field andallow_dynamic_sqlboolean field tostep.db_query_cachedconfig schema; updatedallow_dynamic_sqldescription forstep.db_query,step.db_query_cached, andstep.db_execto reflect the tightened identifier allowlistmodule/pipeline_step_db_query_cached_test.go: Updated existing tests for legacy flat output (nomode) and newrow/foundshape (explicitmode: single); added coverage for list mode (cache miss/hit/empty), invalid mode rejection, explicit single mode found/not-found, dynamic table name, and SQL injection rejectionOutput format
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.