[Bug]: update_fields returns 200 "fields updated" for type changes it does not apply
Bug Description
This is split out from #14744, which reports it alongside a DB Monitoring failure. #14984 fixes the DB Monitoring part and leaves this one, which affects every stream, not just DB Monitoring.
PUT /api/{org}/streams/{stream}/update_fields answers 200 {"message":"fields updated"} for type changes it does not apply. Changing an existing Utf8 field to Int64, UInt64, Float64 or Boolean leaves it Utf8, and the response says the change worked. From Utf8, the only change that is applied is to LargeUtf8.
update_fields_type (src/stream/src/lib.rs) sends the requested types through handle_diff_schema, the path ingestion uses when a record arrives with a new type. That path changes a field's type only when is_widening_conversion (src/infra/src/schema/mod.rs) allows it. Both the pre-check (get_schema_changes in src/schema/src/lib.rs) and the merge (get_merge_schema_changes) apply that rule. For any other change the schema is left as it was. update_fields_type ignores the result and returns Ok(()), and the handler reports that as 200. Nothing applies the requested type later.
Steps to Reproduce
POST /api/default/uf_logs/_jsonwith[{"status_code": "200", "count": 5}]. This makesstatus_codeaUtf8field andcountanInt64one.PUT /api/default/streams/uf_logs/update_fields?type=logswith{"fields":[{"name":"status_code","data_type":"Int64","nullable":true}]}.GET /api/default/streams/uf_logs/schema?type=logs.
Results on a local build of main (97c0905ac; nothing on this path has changed on main since). The schema was re-read for 10 seconds after each request:
| request | response | type afterwards |
|---|---|---|
status_code Utf8 → Int64 |
200 fields updated |
Utf8 |
status_code Utf8 → Float64 |
200 fields updated |
Utf8 |
status_code Utf8 → Boolean |
200 fields updated |
Utf8 |
traces stream, db_response_returned_rows Utf8 → Int64 (the #14744 case, from an OTLP intValue) |
200 fields updated |
Utf8 |
count Int64 → Float64 (a widening change) |
200 fields updated |
Float64 |
status_code → Int32 (a type name it does not support) |
400 Unsupported data_type 'Int32' for field 'status_code' |
Utf8 |
The endpoint already rejects a type name it does not know. It does not check whether a change it accepted was applied.
Expected
A 200 should mean the field now has the requested type. When a change to an existing field cannot be applied, the request should fail with a 400 that names the field and says the conversion is not supported. That is how #14338 made update_fields and delete_fields reject reserved columns instead of reporting success.
A small fix would check each requested field in update_fields_type before calling handle_diff_schema. If the field already exists and the requested type is neither its current type nor a widening of it (is_widening_conversion(current, requested)), return that 400.
Environment Details
Version: main, commit 97c0905ac (local build)
Deployment: single node, local mode (SQLite, local disk)
OS: macOS (arm64)Is this a regression?
Not as far as I can tell.
Related
- #14744 reports this alongside the DB Monitoring failure; it is that issue's third suggested fix. #14984 fixes only the DB Monitoring part.
- #14338 (fixing #14331) added the reserved-column guard to the same two endpoints.
Source: openobserve/openobserve