Repository navigation
fix(api): a query-string "false" is false — the office Jobs list was filtering out every job - #862
Merged
Merged
Conversation
…filtering out every job
`GET /v1/office/jobs` validated `myTeamsOnly` with `z.coerce.boolean()`,
which is `Boolean(value)`. A query string carries only strings, and
`Boolean("false")` is `true`, so every value of the flag arrived as on.
That compounds: a truthy `myTeamsOnly` switches the `job_team_assignments`
embed to an inner join and then filters to the caller's own team
memberships. The office Jobs screen always sends the param — it is
`useState(false)` in `office-jobs-list.tsx` — so the list could never
show a job. Measured locally against thirteen seeded jobs:
?limit=100 -> 13
?limit=100&myTeamsOnly=false -> 0
?limit=100&myTeamsOnly=true -> 0
No error, no warning: just "No jobs found".
`booleanQueryParam` in `_shared/query-schemas.ts` replaces it. It reads
`true`/`false` and `1`/`0`, case- and whitespace-insensitively, passes a
real boolean through so `.default(false)` works, and rejects anything
else with a validation error rather than guessing. `work-logs.ts` had the
same `z.coerce.boolean()` on `includeArchived` and moves onto it too;
those were the only two in the routes.
Three other routes hand-roll the same parse correctly
(notifications.ts:59, teams.ts:87, organizations-extended.ts:981). They
are left alone here — unifying them is a tidy-up, not a fix, and each has
its own default-on-garbage behaviour worth reading before changing.
Closes #857
Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
📊 Performance Benchmark Results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #857. Found by the release-1 route sweep (#852).
The bug
GET /v1/office/jobsvalidatedmyTeamsOnlywithz.coerce.boolean(), which isBoolean(value). A query string carries only strings, andBoolean("false")istrue, so every value of the flag arrived as on.That compounds at
office-jobs.ts:106: a truthymyTeamsOnlyswitches thejob_team_assignmentsembed to an inner join, and:160then filters to the caller's own team memberships. The office Jobs screen always sends the param — it isuseState(false)inoffice-jobs-list.tsx:106,127— so the list could never show a job.Measured locally against thirteen seeded jobs:
?limit=100?limit=100&myTeamsOnly=false?limit=100&myTeamsOnly=trueNo error, no warning — just "No jobs found" on a screen with thirteen jobs behind it.
The fix
booleanQueryParaminfunctions/_shared/query-schemas.ts:z.coerce.boolean()booleanQueryParam"true""false""1""0""yes"Written as a
preprocessaroundz.boolean()so a real boolean passes through and.default(false)works at the call site.work-logs.ts:564had the samez.coerce.boolean()onincludeArchivedand moves onto it too; those were the only two in the routes.Three other routes hand-roll the same parse correctly (
notifications.ts:59,teams.ts:87,organizations-extended.ts:981). Left alone here — unifying them is a tidy-up, not a fix, and each has its own behaviour on a garbage value worth reading before changing.Verification
tests/unit/query-schemas.test.ts— 8 tests, run and passing. Pins"false"→ false, the numeric and uppercase spellings, a real boolean passing through, rejection of unrecognised values, and absent staying distinct from false.tests/routers/office-jobs-rest.test.ts— 3 tests, written, not run here. They exercise the real handler and assert the equivalence that matters:myTeamsOnly=falsereturns what omitting it returns. The local edge runtime serves the main checkout, not this worktree, so these run in the normal api-test flow rather than in this session. Both files typecheck under the tests' deno config.pnpm prepushclean.🤖 Generated with Claude Code