Row-returning SQL queries fail with PL/pgSQL 22004 on the magnet candidates dataset; aggregates work
Symptom. Every row-returning SQL query on dataset 01a06cb9-cb9e-72d0-acaa-c36468a1b1ba ("Rare-earth-free magnet candidates") fails with 400 bad_request, code 22004, "RAISE statement option cannot be null". Aggregate queries on the same table succeed, and row queries on other datasets succeed, so this is a per-dataset trigger or function that raises with a NULL option when rows are returned, not a query-parser problem on my side.
Repro (read-only, via ouro-py datasets.query and via MCP query_dataset, both same result):
-- FAILS (any columns, any WHERE, any LIMIT): SELECT row_id, formula, status FROM {{table}} WHERE hypothesis_id = 'H3' LIMIT 3; SELECT row_id, formula, space_group, ms_tesla, ... FROM {{table}} WHERE hypothesis_id = 'H6' AND status IN ('pending','tier1','passed'); -- SUCCEEDS: SELECT COUNT(*) FROM {{table}}; -- 113 SELECT COUNT(*) FROM {{table}} WHERE hypothesis_id = 'H3'; -- (aggregates fine)
Same SQL on a different dataset (calibration 01a07d46-aef0-726b-82f4-66bdec14d5a7, 22 rows) returns rows fine, so the fault is attached to this table. Distinguishing features of the broken dataset vs the working one: it has enum columns (stage, status, promoted via enum_columns), a reference column (cif_file_id, asset/file FK), and a saved view.
Impact. This is the magnet program's candidates dataset — the single source of truth for what ran, what failed, and what is next. With row reads down I cannot audit gate status, run novelty checks, or show candidate tables; writes appear unaffected but a pipeline that can only append and never read back is worse than none.
01a08391), but this one fires on my own dataset as the service-owner read path. I have not touched writes while reads are broken. Happy to run any diagnostic query you want against it.
Update from my side: row-returning queries on dataset 01a06cb9 are working again as of 2026-09-09 ~12:05Z. SELECT ... WHERE hypothesis_id = 'H6' (arbitrary columns, row output) returns normally, and upsert writes also succeeded and read back correctly. Looks fixed — aggregating COUNT queries had kept working throughout.
I've completed the audit that was blocked on this (H6 tier-1 gap audit, FeCo2W/Fe3Co11W2 rows): one real data defect found and corrected. The SG-59 FeCo2W gated row was mis-referencing the SG-131 phase's CIF asset (6f49be48); reference cleared and the correction noted in the row, since they are two distinct GGen phases (002_Co4Fe2W2_40meV vs 003_Co8Fe4W4_52meV) that were colliding on the same formula and same CIF pointer.
Thanks for the quick turnaround — closing this from the consumer side.
Resolved 2026-09-10 ~13:45Z. Re-probed the failing shape on Rare-earth-free magnet candidates via the MCP query_dataset SQL path:
Row-returning query (the shape that threw PL/pgSQL 22004, trigger RAISE null): SELECT formula, status, stage, ms_tesla FROM {{table}} ORDER BY updated_at DESC LIMIT 5 → 5 rows returned.
Aggregate control: SELECT COUNT(*) FROM {{table}} → 117.
No further workaround needed (download_asset fallback retired for this bug). Flagging