Skip to content

fix(traceql): render an empty selector without panicking - #1057

Merged
rita7lopes merged 1 commit into
metrico:masterfrom
Guess-Who-sec:fix/traceql-empty-selector-string
Nov 3, 2026
Merged

rita7lopes merged 1 commit into
metrico:masterfrom
Guess-Who-sec:fix/traceql-empty-selector-string

Conversation

@Guess-Who-sec

Copy link
Copy Markdown
Contributor

What

Two nil checks in reader/traceql/traceql_parser/model_v2.go, plus tests:

  • Selector.String() renders an empty selector as {}, as CompareSelector.String() already does. It used to dereference the nil AttrSelector.
  • AttrSelectorExp.String() no longer dereferences a nil Tail when AndOr is set.

Why

String() panicked on valid queries with an empty selector:

Query Before After
{}, { } panic {}
{ } | rate() panic {} | rate()
{ } | count() > 1 panic {} | count() > 1
{ } && { .a = 1 } panic {} && {.a = 1}
({ }) panic ({})

It was found while adding parse-render round-trip checks to the parser fuzz targets for M1 (#918).

Impact on users is low. The transpiler does not render the AST on the query path. The only production caller is an error message in clickhouse_transpiler/attr_condition.go.

The parser also accepts { .a = 1 && } and { .a = 1 || }, which are not valid TraceQL, and leaves Tail nil. The second nil check stops String() from panicking on them. Whether the parser should reject that input is a separate change, not made here.

Verification

  • New tests in model_v2_test.go:
    • 7 empty-selector queries must render to the expected text, and that text must render the same way again
    • 2 dangling &&/|| queries must not panic
    • All 9 fail on master and pass here.
  • Rendering is otherwise unchanged. I rendered 72 TraceQL queries on master and on this branch. 64 render identically. The other 8 are the ones that used to panic.
  • gofmt -l . is clean. go build, go test ./... and go test -race ./reader/traceql/... pass.
  • go vet ./... gives the same findings as master. The pre-existing participle struct-tag warnings in model_v2.go moved down by the added lines.

Selector.String() dereferenced AttrSelector, which is nil for an empty
selector, so String() panicked on valid queries such as `{ }`,
`{ } | rate()` and `{ } && { .a = 1 }`. It now renders `{}`, as
CompareSelector.String() already does.

AttrSelectorExp.String() likewise dereferenced Tail whenever AndOr was
set. The parser accepts `{ .a = 1 && }` (not valid TraceQL) with a nil
Tail; String() no longer panics on it. Whether the parser should accept
that input is left for a separate change.

Queries that rendered before render exactly as before: of 72 TraceQL
queries, the only outputs that changed are the 8 that used to panic.

@rita7lopes rita7lopes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a real user impact thing but merging because of #1059

@rita7lopes
rita7lopes merged commit b7afb25 into metrico:master Nov 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants