mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-09-28 19:12:00 +00:00
fix(json-columns): skip JSON select columns with no model scan target
Tests / Unit Tests (push) Failing after 28s
Tests / Integration Tests (push) Failing after 29s
Build , Vet Test, and Lint / Build (push) Successful in 1m12s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 1m43s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 1m46s
Build , Vet Test, and Lint / Lint Code (push) Successful in 1m48s
Tests / Unit Tests (push) Failing after 28s
Tests / Integration Tests (push) Failing after 29s
Build , Vet Test, and Lint / Build (push) Successful in 1m12s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 1m43s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 1m46s
Build , Vet Test, and Lint / Lint Code (push) Successful in 1m48s
Requesting a JSON sub-field (e.g. jsonvalue->'product'->>'cost') that has no matching bun scanonly field on the model made the whole read fail with "bun: ModelX does not have column Y", since bun scans SELECT results straight into the typed model struct. Add reflection.HasColumn to check whether the model can actually receive a given column (including scanonly fields, walking embedded structs), and gate the JSON select-column expression on it in ApplySelectColumns (shared by websocketspec/mqttspec) and the resolvespec/restheadspec handlers. When there's no scan target, drop just that column with a warning instead of erroring the whole request.
This commit is contained in:
@@ -349,6 +349,10 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
|
||||
logger.Debug("Selecting columns: %v", options.Columns)
|
||||
for _, col := range options.Columns {
|
||||
if expr, jargs, alias, ok := common.ResolveJSONColumnExpr(model, "", col); ok {
|
||||
if !reflection.HasColumn(model, alias) {
|
||||
logger.Warn("Skipping JSON select column %q: model has no scan target for alias %q", col, alias)
|
||||
continue
|
||||
}
|
||||
query = query.ColumnExpr(expr+" AS "+common.QuoteIdent(alias), jargs...)
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user