fix: Correctly set authorization model id when calling batch checks#372
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
Fixes batchCheck so it correctly uses the client-level default authorizationModelId when the caller doesn’t explicitly provide one, avoiding repeated “latest model” lookups on the server.
Changes:
- Update
batchCheckto setauthorization_model_idviagetAuthorizationModelId(options)(so it falls back to the client’s configured model ID). - Add a regression test ensuring
batchCheckfalls back to the client’s authorization model ID whenoptions.authorizationModelIdis omitted.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
client.ts |
Ensures batch-check requests include the effective authorization model ID (option override or client default). |
tests/client.test.ts |
Adds coverage for the client-default authorization model ID fallback behavior in batchCheck. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe changes modify how authorization model IDs are resolved in the OpenFGA client by replacing direct option values with calls to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/client.test.ts (1)
1638-1641: Make result assertions order-independent.These assertions assume a stable response array order. Matching by
correlationIdwill make the test less brittle.♻️ Suggested test update
- expect(response.result[0].allowed).toBe(true); - expect(response.result[1].allowed).toBe(false); + const cor1 = response.result.find((r) => r.correlationId === "cor-1"); + const cor2 = response.result.find((r) => r.correlationId === "cor-2"); + expect(cor1?.allowed).toBe(true); + expect(cor2?.allowed).toBe(false);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/client.test.ts` around lines 1638 - 1641, The test currently asserts response.result items by array index which is brittle; update the assertions to be order-independent by locating items by their correlationId instead of array positions. In the test block that checks scope.isDone() and response.result, find the two result objects using response.result.find(r => r.correlationId === '<expected-id>') (or similar) and assert their allowed properties (e.g., foundA.allowed.toBe(true), foundB.allowed.toBe(false)); keep the existing scope.isDone() assertion and replace indexed checks on response.result[0] and response.result[1] with these correlationId-based lookups.client.ts (1)
732-778: Resolve authorization model ID once before batching.
batchCheckcurrently resolves/validates the model ID inside each batch callback. Resolving it once up front is simpler and fails fast before scheduling batch work.♻️ Suggested refactor
const { headers = {}, maxBatchSize = DEFAULT_MAX_BATCH_SIZE, maxParallelRequests = DEFAULT_MAX_METHOD_PARALLEL_REQS, } = options; + const authorizationModelId = this.getAuthorizationModelId(options); setHeaderIfNotSet(headers, CLIENT_BULK_REQUEST_ID_HEADER, generateRandomIdWithNonUniqueFallback()); @@ const batchRequest: BatchCheckRequest = { checks: batch, - authorization_model_id: this.getAuthorizationModelId(options), + authorization_model_id: authorizationModelId, consistency: options.consistency, };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@client.ts` around lines 732 - 778, In batchCheck, call this.getAuthorizationModelId(options) once before creating batchedChecks and store the result (e.g., authorizationModelId) so validation/resolution happens up-front and can fail fast; then use that stored authorizationModelId inside the batchResponses async callback when building batchRequest instead of calling this.getAuthorizationModelId(options) per-batch. Ensure the variable is validated/awaited before asyncPool is invoked and referenced in the batchRequest object alongside options.consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@client.ts`:
- Around line 732-778: In batchCheck, call this.getAuthorizationModelId(options)
once before creating batchedChecks and store the result (e.g.,
authorizationModelId) so validation/resolution happens up-front and can fail
fast; then use that stored authorizationModelId inside the batchResponses async
callback when building batchRequest instead of calling
this.getAuthorizationModelId(options) per-batch. Ensure the variable is
validated/awaited before asyncPool is invoked and referenced in the batchRequest
object alongside options.consistency.
In `@tests/client.test.ts`:
- Around line 1638-1641: The test currently asserts response.result items by
array index which is brittle; update the assertions to be order-independent by
locating items by their correlationId instead of array positions. In the test
block that checks scope.isDone() and response.result, find the two result
objects using response.result.find(r => r.correlationId === '<expected-id>') (or
similar) and assert their allowed properties (e.g., foundA.allowed.toBe(true),
foundB.allowed.toBe(false)); keep the existing scope.isDone() assertion and
replace indexed checks on response.result[0] and response.result[1] with these
correlationId-based lookups.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f5a0a993-86d0-4cac-a02b-5e5ce660e8ac
📒 Files selected for processing (2)
client.tstests/client.test.ts
6441df8 to
35322d1
Compare
|
(no clue why it auto-closed issue which was referenced in private repo 👀) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #372 +/- ##
==========================================
- Coverage 85.80% 85.79% -0.02%
==========================================
Files 26 26
Lines 1268 1267 -1
Branches 225 249 +24
==========================================
- Hits 1088 1087 -1
Misses 110 110
Partials 70 70 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the PR @kamilogorek - expect it to go in a release soon, either tomorrow or next week |
|
Thanks @rhamzeh! btw. this is kind of load difference I referred to in my original description 😄
|

This change fixes a bug where batch checks were not picking up a default authorization model ID which is set on the client level. It causes a huge postgres load unless you manually specify the ID for every call, as it has to fetch the model from the DB on every check.
Review Checklist
mainSummary by CodeRabbit
Bug Fixes
Tests