Repository navigation
Commit 2a3dec2
fix(rest): a refused xlsx export answers the 400 envelope, not a 200 workbook stream (#27888)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DSK85qKE6pSk5Ekis1FkEnW)_
domain:server#4 · os-elon-musk · session_016WV4cyUucJoh7384vix5rh
Fixes #27755
## 维护者速读
- 改了什么:导出接口选 Excel(xlsx)格式时,先读第一页数据,再开始生成工作簿;与 #27753 对 json 的修法相同。
- 为什么改:之前工作簿一打开就把响应定成 200,查询被拒(例如按不存在的字段搜索)时用户拿到的是一个坏的或空的 Excel
文件,而不是说明错误的 400。
- 风险与回滚:改动只有导出函数里的一行挪位;成功导出的状态码、响应头和单元格内容不变。回滚即还原这一行。
- 先看:`packages/rest/src/data-action-routes.ts` 导出循环里新增的
`createXlsxStream` 那一行。
- 两分钟验证:`GET
/api/v1/data/OBJECT/export?format=xlsx&search=x&searchFields=nope` 应回
400 INVALID_FIELD,与 csv 一致;不带错误参数的 xlsx 导出照常下载可打开的工作簿。
- 需要你做的:无;席位复核通过、CI 全绿后按本席落地口径落地。
## What changes
- `packages/rest/src/data-action-routes.ts`: the xlsx export opens its
workbook writer (`createXlsxStream`) after the first `findData` answers,
not before the read loop. The writer is opened inside the loop on the
first chunk, placed before the zero-row break next to json's opening
bracket (#27753), so an empty export is still a readable workbook.
Nothing else in the route changes, and the async import-job region
(#27795) is untouched.
- `packages/rest/src/export-xlsx-refusal-envelope.test.ts` (new): pins
both halves through the real `HonoHttpServer`.
- `.changeset/27755-xlsx-export-read-first.md`: patch for
`@objectstack/rest`.
## Why
Opening the exceljs streaming writer commits the Hono adapter to a
streaming 200. Opening it before the first read meant a query that read
refused reached the client as a 200 workbook download, while
`format=csv` (and, since #27753, `format=json`) answered the 400
envelope. Triage 6510461172: the xlsx writer opens after the first page
is read and answers the same envelope. A refusal on a later page is not
widened here.
## Verification
- Pin, over a real `SqlDriver` (SQLite): `?search=x&searchFields=nope`
(`400 INVALID_FIELD`) and `?search=x&searchFields=,` (`400
VALIDATION_ERROR`) answer the same status and body for `format=xlsx` as
for `format=csv`. Ablation: on the unfixed code both xlsx rows are red
(`expected 200 to be 400`); with the fix, green.
- Preservation: a successful xlsx export over one page, three pages
(`page=50`, 120 rows) and zero rows answers 200, the workbook content
type, `X-Export-Styles: applied`, the same number of reads, and a
workbook that loads with the same cells (header + rows; empty for zero
rows). Green on the unfixed code too, so the success path did not move.
- `dispatch-gates --ran`: 59 derived families, 58 run green, 1 NOT
MEASURED (`check:dual-build-cjs-loads`, exit 3, needs a whole-tree
build). `pnpm lint` green. After merging `main` (which brought #27795):
`@objectstack/rest` `tsc --noEmit` green and full suite green (353
files, 7027 passed, 350 skipped); the derived gate list is unchanged.
Clause-②: no
Metadata-protocol: none
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cyUucJoh7384vix5rh
Co-authored-by: Claude <noreply@anthropic.com>1 parent d770b15 commit 2a3dec2
3 files changed
Lines changed: 180 additions & 1 deletion
File tree
- .changeset
- packages/rest/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1457 | 1457 | | |
1458 | 1458 | | |
1459 | 1459 | | |
1460 | | - | |
| 1460 | + | |
1461 | 1461 | | |
1462 | 1462 | | |
1463 | 1463 | | |
| |||
1507 | 1507 | | |
1508 | 1508 | | |
1509 | 1509 | | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
1510 | 1516 | | |
1511 | 1517 | | |
1512 | 1518 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
0 commit comments