Skip to content

bug: TRUNCATE via /v1/query returns HTTP 500 #118

Description

@jfwoods

Description

Query endpoint chokes on a no-rows result.

Steps to Reproduce

  1. Spin up WaveHouse (ghcr.io/wave-rf/wavehouse:dev) and Clickhouse, populate schema
  2. Run TRUNCATE on query endpoint, before any events have entered the database

Expected Behavior

Not sure-- some possible options:

  1. Return HTTP 200: I guess, if you want a 0-row DB, you now have a zero row DB?
  2. Return HTTP 409
  3. Return HTTP 412

Decision for alpha

Recommend HTTP 200 — TRUNCATE is idempotent DDL. Running it against an already-empty table is functionally a no-op success; returning 4xx implies the request was bad, which it wasn't. ClickHouse itself returns success on this case. Treat the 500 as a handler bug where a 0-row response shape isn't being marshaled correctly, not as an intentional error.

If anyone disagrees, settle before tagging v0.1.0-alpha.1 — the response code is part of the public API surface.

Actual Behavior

Return HTTP 500

Environment

  • WaveHouse version: dev-tagged image from commit d100ef6
  • OS: (Linux)
  • Hardware: AWS EC2 (t3.micro)

Logs

    >>  ID="$(../scripts/tf output -raw worker_access_token_id 2>/dev/null)" && SEC="$(../scripts/tf output -raw
      worker_access_token_secret 2>/dev/null)" && \
      H=( -H "CF-Access-Client-Id: $ID" -H "CF-Access-Client-Secret: $SEC" ) && B="https://wavehouse.demo.wavehouse.dev" && \
      echo "=== ingest one more then SSE (since ~now-1m, 6s) ===" && \
      ( sleep 1 && curl -sS -m 10 "${H[@]}" -X POST "$B/v1/ingest/demo_events" -H 'content-type: application/json' -d
      '{"event_id":"verify-wavehouse-sse","session_id":"verify","control":"btn-clickme-2","action":"click","value":2,"orig_ts":"'"$(date
       -u +%Y-%m-%dT%H:%M:%S.000Z)"'","emit_ts":"'"$(date -u +%Y-%m-%dT%H:%M:%S.050Z)"'"}' >/dev/null ) & \
      curl -sN -m 6 "${H[@]}" "$B/v1/stream/sse?topic=ingest.demo_events&since=$(date -u +%Y-%m-%dT%H:%M:%SZ -d '-1 min' 2>/dev/null ||
      date -u -v-1M +%Y-%m-%dT%H:%M:%SZ)" 2>&1 | head -c 800 ; wait; echo; echo "(sse done)" && \
      echo "=== truncate the verify rows ===" && curl -sS -m 10 "${H[@]}" -X POST "$B/v1/query" -H 'content-type: application/json' -d
      '{"sql":"TRUNCATE TABLE wh.demo_events"}' -o - -w ' -> HTTP %{http_code}\n' && \
      curl -sS -m 10 "${H[@]}" -X POST "$B/v1/query" -H 'content-type: application/json' -d '{"sql":"SELECT count() AS n FROM
      wh.demo_events"}' -o - -w ' -> HTTP %{http_code}\n')
 
 === ingest one more then SSE (since ~now-1m, 6s) ===
     id: 2026-05-12T17:11:46.736779321Z
     data: {"data":{"action":"click","control":"btn-clickme-1","emit_ts":"2026-05-12T17:00:00.050Z","event_id":"verify-wavehouse-1"

Activity

  1. added theissue type on May 12, 2026
  2. EricAndrechek commented on May 18, 2026

    @EricAndrechek
    Member

    Update: evaluate flow and response codes on DELETE, UPDATE, etc, and if we can/should fit into this release, or have them all only be via admin SQL

  3. moved this from Backlog to Ready in WaveHouse Task Boardon May 18, 2026
  4. taitelee commented on May 18, 2026

    @taitelee
    Member

    The 500 error here raised discussion about how should mutation statements like TRUNCATE, DELETE, and UPDATE be exposed and authorized. We've settled this in #158: those statements are only valid through POST /v1/query under an admin/service role (or a policy role with RawSQL: true), and all other pipelined paths that perform them are being removed.

    Agreeing with the recommendation from the bug report, running TRUNCATE on an already empty table should succeed (HTTP 200) and return an empty array ([]), just like ClickHouse does. We will include this fix in PR #158. Since #158 makes /v1/query the single endpoint for these operations, it is the best place to handle the clean formatting of zero-row results.

  5. moved this from In progress to Done in WaveHouse Task Boardon May 20, 2026
  6. added a commit that references this issue on May 20, 2026
    e07d5ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/apiHTTP handlers, routing, middlewarearea/queryStructured query AST, SQL builderbreaking-changeBreaking change to public API, CLI, or configbugSomething isn't working

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions