Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js-sdk: Batch check does not preserve output order #347

Open
6 of 10 tasks
a0js opened this issue Apr 19, 2024 · 1 comment
Open
6 of 10 tasks

js-sdk: Batch check does not preserve output order #347

a0js opened this issue Apr 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@a0js
Copy link

a0js commented Apr 19, 2024

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Slack Community and have not found a suitable solution or answer.
  • I agree to the terms within the OpenFGA Code of Conduct.

Description

When using the batch check functionality in the js-sdk, the check results are not returned in the same order as the input. Based on what I've found in the python sdk, the order is preserved.

Expectation

I would expect when an array is provided as input, and the expected output is an array of equal length, order should be preserved.

Reproduction

Run the following:

const { OpenFgaClient } = require('@openfga/sdk');
const assert = require('assert');
const util = require('util');

const fgaClient = new OpenFgaClient({apiUrl: "https://api.playground.fga.dev", storeId: "01HVW8AJAT069Y9M1FZDKV6SP0", authorizationModelId: "01HVW8C9JP1XS2ZZG614S8KH47"});

async function test() {
	const checks = [
	{
		user: "user:1",
		relation: "test",
		object: "object:2"
	},
		{
		user: "user:1",
		relation: "test",
		object: "object:2",
		contextualTuples: [{
			user: "user:1",
			relation: "test",
			object: "object:2"
		}]
	},
		{
		user: "user:1",
		relation: "test",
		object: "object:1"
		}
	];


	const results = await fgaClient.batchCheck(checks);
	console.log(util.inspect(results, false, null, true));

	assert.deepEqual(results.responses[0]._request, checks[0]);
	assert.deepEqual(results.responses[1]._request, checks[1]);
	assert.deepEqual(results.responses[2]._request, checks[2]);
}

test();

This hits this model: https://play.fga.dev/sandbox/?store=js-sdk-batch-ordering

SDK Checklist

  • JS SDK
  • Go SDK
  • .NET SDK
  • Python SDK
  • Java SDK

OpenFGA SDK version

0.3.5

OpenFGA version

any

SDK Configuration

any

Logs

No response

References

This issue seems to be related to the cause rxaviers/async-pool#47

@a0js a0js added the bug Something isn't working label Apr 19, 2024
@rhamzeh
Copy link
Member

rhamzeh commented Apr 22, 2024

Hi @a0js - batch check is not intended to preserve the output order. While we can sort before returning the results, that would be offering a contract we are not certain we want to promise for the future.

Especially with the potential to offer a streaming variant of the API.

Each response has the request alongside it so that you can know what the result is for.

@rhamzeh rhamzeh added enhancement New feature or request and removed bug Something isn't working labels Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants