You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 521b4f6
Browse filesBrowse the repository at this point in the historyBrowse files
fix(driver-sql): on Oracle, a composed ReadableIds scope primes its RAW(16) parent's uuid columns (#36084)
Fixes#35960
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:在 Oracle 外部表上,主键为十六字节二进制 uuid
的父对象,其子记录按父记录可见性读取时,现在第一次读就返回应有的记录,取反也只返回其余记录。
- 为什么做:数据权限里“按父记录控制可见性”的子对象在 Oracle 上静默读空,替用 Oracle 外部表的部署解决这个问题。
- 出错会怎样:只影响 Oracle 驱动在读子对象前多读一次父表的列类型;若读取失败则按原来的方式绑定,可直接撤回本次改动。
- 要你做什么:无。
## What changes
On Oracle, a door primes a federated table's `RAW(16)` uuid columns from
the catalog before it binds a comparand (`primeOracleRawUuidColumns`).
It primed only the door's own object, so a composed `ReadableIds` scope
naming a `RAW(16)`-keyed parent bound the parent's ids as text: the
child read answered no row and its negation every row, until something
read the parent on that driver.
- `sql-driver-field-mapping.ts`: `primeOracleRawUuidColumns(object,
where?)` now primes the door's object and every object a composed
`ReadableIds` leaf in `where` names, at any depth. It reuses the
existing walk `collectTextMatchObjects` (the SQL Server GUID prime's),
ignoring its text-operator answer, so there is still one walk.
- Every Oracle door that primes with a filter in hand passes it:
`find`/`findOne` (`findRows`), `count`, `distinct`, `updateMany`,
`deleteMany`, `aggregate` (its where plus measure filters, folded once
into `primedWhere` for all three primes, and each joined parent's
scope), `findWithWindowFunctions`, `analyzeQuery`.
- `sql-driver.ts`: the stub takes and forwards `where`; its docblock
says what it now primes.
- Doors with no filter (`create`, `bulkCreate`, `update`, `delete`,
`bulkDelete`) are unchanged. Every other dialect is unchanged (the body
returns on `!isOracle` first).
Read first, by risk: `sql-driver-field-mapping.ts` (the prime body, the
loop over objects), `sql-driver-aggregation.ts` (the `primedWhere` hoist
feeds the SQL Server and PostgreSQL primes too),
`sql-driver-fixed-read-leaf-conformance.test.ts` (the new describe).
## Tests
New live pin in `sql-driver-fixed-read-leaf-conformance.test.ts`, on the
Oracle testkit cell (`ORACLE_CELL`, gvenzl/oracle-free
23-slim-faststart): `a composed scope's RAW(16) parent is primed by the
child's own door: a fresh driver, the child read first`. Each case
builds a fresh `SqlDriver`, and the child read is its first statement.
Two forms: the LIST form `{ id: { $in: [U1 upper-case, U2] } }` inside
the composed scope, and the share-grant leaf. Ten cases each: find `[c1,
c2]`, the negation `[c4]`, count 2, the negation's count 1, distinct,
aggregate (where and measure filter), `findWithWindowFunctions`,
`analyzeQuery` (statement carries `HEXTORAW(`), `updateMany`,
`deleteMany`.
The existing nested pin no longer reads the parent first; its comment
said the child's door primes the child alone, which is no longer true.
<details><summary>Measured on main 8145424 before the fix: 20 of 20
red</summary>
```
Tests 20 failed | 80 skipped (100)
AssertionError: expected [] to deeply equal [ 'c1', 'c2' ]
AssertionError: expected [ 'c1', 'c2', 'c4' ] to deeply equal [ 'c4' ]
AssertionError: expected +0 to be 2
AssertionError: expected 3 to be 1
AssertionError: expected 'select * from "SRIDO_CHILD" where "PA…' to contain 'HEXTORAW('
```
</details>
<details><summary>With the fix, at head 1924389: both Oracle live
files green</summary>
```
src/sql-driver-fixed-read-leaf-conformance.test.ts + src/sql-driver-oracle-federation-conformance.test.ts
Test Files 2 passed (2)
Tests 365 passed | 2 skipped (367) (20 of 20 pin cases pass)
os-verify-lock: VERDICT command-exit 0
```
</details>
<details><summary>Ablation: the walk call removed, pin red, restored to
HEAD</summary>
`node scripts/ablation-replace.mjs` replaced the line
`collectTextMatchObjects(where, objects);` in the Oracle prime with a
marker (anchor 1 to 0, blob bb3b7d9 to 73e309341315), ran the pin:
`Tests 20 failed | 80 skipped (100)`. Restored: blob equals HEAD
(bb3b7d9), `git diff HEAD` empty. The test imports the driver from
`src/`, so no rebuild is involved. A first attempt was refused by the
tool before any test ran (its replacement text already appeared in the
anchor, so the count did not rise); it measured nothing.
</details>
<details><summary>Package suite and typecheck</summary>
- `pnpm --filter @objectstack/driver-sql test` (Oracle cell on), at
0c200dd: `Test Files 268 passed | 13 skipped (281)`, `Tests 4686
passed | 258 skipped (4944)`, VERDICT command-exit 0. The later head
1924389 only removes two `as any` casts in the pin.
- `pnpm --filter @objectstack/driver-sql typecheck`: exit 0, and `tsc
--noEmit` again at 1924389: exit 0. `--listFiles` includes the
conformance test file (1 hit).
</details>
## Acceptance notes
- `findWithWindowFunctions` on a federated Oracle object: a window
spec's `orderBy`/`partitionBy` field is not mapped through
`external.columnMap` (`ORDER BY "id"` gives ORA-00904 on a table whose
column is `ID`), and Oracle refuses `ROW_NUMBER() OVER ()` without an
ORDER BY (ORA-30485). The pin orders by the stored column `ID` and says
so. Not filed: the door has no producer outside the driver packages (the
request surface tombstones `windowFunctions`; `git grep
findWithWindowFunctions` outside the drivers hits only CHANGELOG files).
- Aggregate's joined parent now primes the objects its own scope
composes, too (same walk). That deeper path is not pinned live here: the
fixture has no grandparent.
## Verification
Two-minute check: with an Oracle Free container running and
`OS_TEST_ORACLE_URL=oracle://USER:PASSWORD@127.0.0.1:PORT/FREEPDB1`, run
`pnpm --filter @objectstack/driver-sql exec vitest run
src/sql-driver-fixed-read-leaf-conformance.test.ts -t 'fresh driver, the
child read first'`
and expect `Tests 20 passed`. On main the same command answers `20
failed`.
<details><summary>Local gates (derived by dispatch-gates
--commands)</summary>
`node scripts/pm/dispatch-gates.mjs --ran` on the exit-coded record: `72
derived famil(ies) accounted for — 70 run, 2 NOT-MEASURED (2 DERIVED
from a recorded exit 3)`. The 70 ran at 0c200dd with exit 0
(`check:query-options-erasure` went red there, +1 test-surface site from
two casts in the pin; the casts were removed and it is green at
1924389). Re-run at 1924389, all exit 0:
`check:test-source-alias`, `check:cross-package-test-inputs`,
`check:nul-bytes`, `check:issue-citations`, `check:doc-authoring`,
`check:driver-conformance`, `check-empty-changeset`,
`check-changeset-no-major`, `check-adr-0087-registration`.
NOT MEASURED: `check:dual-build-cjs-loads` and
`check:lean-entry-closure`, reason: PREREQUISITE NOT MET (exit 3). They
read the whole repo's built output and only driver-sql's dependency
closure was built. CI runs them.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibwJEh7hMPPvagWM1g7)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(driver-sql): on Oracle, a read scoped by a parent with a RAW(16) uuid key answers its rows on a driver that has not read the parent yet
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
A child read whose composed `ReadableIds` scope names a federated parent with a `RAW(16)` uuid key, such as the read plugin-security derives for a `controlled_by_parent` object, answered no row on Oracle, and its negation answered every row, with no error. It recovered only once something had read the parent on that driver. The driver reads a federated table's `RAW(16)` columns from the Oracle catalog before it binds a comparand, and it read them for the door's own object only, so the parent's ids bound as text and Oracle compared them with the column's upper-case hex.
11
+
12
+
Each door that compiles a filter (`find`, `findOne`, `count`, `distinct`, `aggregate`, its measure filters and its joined parents, `updateMany`, `deleteMany`, `findWithWindowFunctions` and `analyzeQuery`) now also reads the `RAW(16)` columns of every object a composed `ReadableIds` scope in that filter names, at any depth. The parent's ids bind through `HEXTORAW`, for a list of ids and for the share-grant subquery alike. Nothing changes for any other dialect.
0 commit comments