feat!: add support for BatchCheck API#154
Merged
ewanharris merged 8 commits intomainfrom Dec 18, 2024
Merged
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #154 +/- ##
==========================================
+ Coverage 68.95% 69.49% +0.53%
==========================================
Files 124 133 +9
Lines 9864 10554 +690
==========================================
+ Hits 6802 7334 +532
- Misses 3062 3220 +158 ☔ View full report in Codecov by Sentry. |
4 tasks
jimmyjames
reviewed
Dec 12, 2024
Contributor
jimmyjames
left a comment
There was a problem hiding this comment.
Generally looks great, a couple questions and a nit. I'll spend some more time in greater depth tomorrow looking at it.
Contributor
|
Changes LGTM 👍 |
jimmyjames
reviewed
Dec 17, 2024
Contributor
jimmyjames
left a comment
There was a problem hiding this comment.
@ewanharris we should also update the repo's telemetry docs with the new attribute: https://github.com/openfga/python-sdk/blob/main/docs/opentelemetry.md
3458e44 to
911c3f9
Compare
BREAKING CHANGE: Usage of the existing batch_check should now use client_batch_check instead, additionally the existing BatchCheckResponse has been renamed to ClientBatchCheckClientResponse.
911c3f9 to
39cd0b0
Compare
39cd0b0 to
9e8399a
Compare
Helps show the correlation_id use
9e8399a to
36f5016
Compare
jimmyjames
approved these changes
Dec 18, 2024
6 tasks
ekassos
added a commit
to comppolicylab/pingpong
that referenced
this pull request
Jan 12, 2026
…lts (#1194) Resolves an issue where the server may infer incorrect permissions based on the responses from the authentication server. Starting in `openfga-sdk v0.9.0`, a breaking change was introduced to accommodate the new OpenFGA server based batch check. The side effect is that our client can no longer rely on the order of the results returned to construct the checks passed. Adds an index-based `correlation_id` and uses it to order the results before returning to the caller. > #### "I want to migrate to the new server based batch check" > If you wish to migrate to the new method, whilst the method name remains the same. You will need to alter the way you construct the checks passed. > > * Previously a list of `ClientCheckRequest` was constructed and passed directly to `batch_check`, now you should construct a list of `ClientBatchCheckItem` and pass a `ClientBatchCheckRequest` to `batch_check` with that list as the `checks` property > > * The `correlation_id` on a `ClientBatchCheckItem` is set for you if you do not provide it. > * The `result` now contains a `correlation_id` property in addition to the `error` and `request` types and has removed the `response` property. Additionally, the `error` property is now of a `CheckError` type, rather than an `Exception` type. > > ```diff > checks = [ > - ClientCheckRequest( > + ClientBatchCheckItem( > user="user:1", > relation="owner", > object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", > contextual_tuples=[ > ClientTuple( > user="user:1", > relation="owner", > object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", > ) > ] > ), > - ClientCheckRequest( > + ClientBatchCheckItem( > user="use:2", > relation="owner", > object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" > ) > ] > > - result = fga_client.client_batch_check(checks) > + result = fga_client.batch_check(ClientBatchCheckRequest(checks=checks)) > > # response.result = [{ > # allowed: true, > # correlation_id: "de3630c2-f9be-4ee5-9441-cb1fbd82ce75", # generated by the SDK > # tuple: { > # user: "user:1", > # relation: "viewer", > # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", > # contextual_tuples: [{ > # user: "user:1", > # relation: "editor", > # object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" > # }] > # } > # }, { > # allowed: false, > # correlation_id: "6d7c7129-9607-480e-bfd0-17c16e46b9ec", > # tuple: { > # user="user:2", > # relation="own", > # object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" > # }, > # error: { > # input_error: "validation_error", > # message: "type 'doc' not found" > # } > # }] > ``` > ## References * [openfga/python-sdk#154](openfga/python-sdk#154) * [openfga docs: Calling Batch Check API](https://openfga.dev/docs/getting-started/perform-check#03-calling-batch-check-api)
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.
BREAKING CHANGE: Usage of the existing batch_check should now use client_batch_check instead,
additionally the existing BatchCheckResponse has been renamed to ClientBatchCheckClientResponse.
Description
This PR introduces a method for using the
BatchCheckAPI released in OpenFGA v1.8.0, in order to facilitate this it includes a breaking change where the existingbatch_checkmethod (and associated type) has been renamed toclient_batch_check. This is so that our naming conventions remain consistent.Migration
"I want to continue using client side batch check"
Given that this necessitates an upgrade of OpenFGA, it might not be feasible for everyone to switch to the new server based method, if you wish to delay the migration, rename the existing usage to the new method name as shown below.
"I want to migrate to the new server based batch check"
If you wish to migrate to the new method, whilst the method name remains the same. You will need to alter the way you construct the checks passed.
ClientCheckRequestwas constructed and passed directly tobatch_check, now you should construct a list ofClientBatchCheckItemand pass aClientBatchCheckRequesttobatch_checkwith that list as thecheckspropertycorrelation_idon aClientBatchCheckItemis set for you if you do not provide it.resultnow contains acorrelation_idproperty in addition to theerrorandrequesttypes and has removed theresponseproperty. Additionally, theerrorproperty is now of aCheckErrortype, rather than anExceptiontype.References
openfga/sdk-generator#459
Review Checklist
mainBREAKING CHANGE: Usage of the existing batch_check should now use client_batch_check instead,
additionally the existing BatchCheckResponse has been renamed to ClientBatchCheckClientResponse.