authzed / spicedb

Open Source, Google Zanzibar-inspired database for scalably storing and querying fine-grained authorization data
https://authzed.com/docs
Apache License 2.0
5.1k stars 279 forks source link

`BulkCheckPermission` does not return results in the same order as requests #1563

Closed tadejsv closed 1 year ago

tadejsv commented 1 year ago

What platforms are affected?

linux, macos, windows

What architectures are affected?

amd64, arm64

Steps to Reproduce

I have noticed that in some cases, BulkCheckPermission returns the results (permissions) in a different order than requests.

Expected Result

I think the desired behavior would be to return results in the same order as requests

Actual Result

-

josephschorr commented 1 year ago

@tadejsv This is by design: The bulk check permissions has a streaming response and will returns results as they are computed; this is why each returned result contains a pair that includes the initial request: to ensure it can be correlated with the request that created the response

tadejsv commented 1 year ago

But it doesn't actually have a streaming response?

tadejsv commented 1 year ago

@josephschorr https://github.com/authzed/api/blob/main/authzed/api/v1/experimental_service.proto#L48

josephschorr commented 1 year ago

I guess that was changed at some point... we can look into reordering the response then, although the intent is still to use the request information from the pairs for correlation, not the order

bradengroom commented 1 year ago

+1 to ordered results. It makes the APIs really ergonomic from the client's perspective.

# pseudocode
resources = resources_to_check = [...]
responses = spiceDB.bulk_check(resources)
authorized_resources = [
    resource
    for resource, response in zip(resources, responses)
    if response  # filter down to access granted
]