From 6934919534018c3867103cfa7a63a3b4c1c1db2a Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Wed, 8 Oct 2025 17:19:25 -0400 Subject: [PATCH 1/2] feat: ignore duplicate writes on import --- CHANGELOG.md | 3 +++ go.mod | 4 ++-- go.sum | 4 ++-- internal/tuple/import.go | 4 ++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a10422..f46e220d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ Added: * When `--max-pages!=0` (limited pages), defaults to 50 to maintain backward compatibility * Custom page size can be specified with `--page-size` flag +Changed: +- Import now ignores duplicate tuples instead of failing the import. Note: this feature requires OpenFGA server [v1.10.0](https://github.com/openfga/openfga/releases/tag/v1.10.0) or later. You can still import to previous versions, but this setting will be ignored. Writes that are not imports (aka. writing a single tuple instead of from a file) will still fail on duplicates. + ## [0.7.4] - 2025-08-15 Changed: diff --git a/go.mod b/go.mod index 551ef8ad..c72c8572 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/openfga/cli go 1.24.0 -toolchain go1.24.6 +toolchain go1.25.1 require ( github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 @@ -13,7 +13,7 @@ require ( github.com/nwidger/jsoncolor v0.3.2 github.com/oklog/ulid/v2 v2.1.1 github.com/openfga/api/proto v0.0.0-20250909172242-b4b2a12f5c67 - github.com/openfga/go-sdk v0.7.2 + github.com/openfga/go-sdk v0.7.3 github.com/openfga/language/pkg/go v0.2.0-beta.2.0.20250919191407-efa08b02a76a github.com/openfga/openfga v1.10.2 github.com/rung/go-safecast v1.0.1 diff --git a/go.sum b/go.sum index 83c56d47..eb219deb 100644 --- a/go.sum +++ b/go.sum @@ -176,8 +176,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/openfga/api/proto v0.0.0-20250909172242-b4b2a12f5c67 h1:58mhO5nqkdka2Mpg5mijuZOHScX7reowhzRciwjFCU8= github.com/openfga/api/proto v0.0.0-20250909172242-b4b2a12f5c67/go.mod h1:XDX4qYNBUM2Rsa2AbKPh+oocZc2zgme+EF2fFC6amVU= -github.com/openfga/go-sdk v0.7.2 h1:qbklIm0hjPDnCCjGkgr1X32v46agEYzYiANYribPO5s= -github.com/openfga/go-sdk v0.7.2/go.mod h1:kiryf3FszAobRaQiBSbCpxBxuSh0SpSMt94ivduaIWc= +github.com/openfga/go-sdk v0.7.3 h1:BrYmJyIdicVeKzoycCFT0vzf0oz4luWrwoPIJdF6Wgo= +github.com/openfga/go-sdk v0.7.3/go.mod h1:kiryf3FszAobRaQiBSbCpxBxuSh0SpSMt94ivduaIWc= github.com/openfga/language/pkg/go v0.2.0-beta.2.0.20250919191407-efa08b02a76a h1:mwpFZZdH4B6hHDGuQjkvebkp8+eLEi63nZ8XniGTyvo= github.com/openfga/language/pkg/go v0.2.0-beta.2.0.20250919191407-efa08b02a76a/go.mod h1:BG26d1Fk4GSg0wMj60TRJ6Pe4ka2WQ33akhO+mzt3t0= github.com/openfga/openfga v1.10.2 h1:7dw9AatGYuhNTs0e5zsAaetIzV8sePbAeaBai5ibvZs= diff --git a/internal/tuple/import.go b/internal/tuple/import.go index 4a1c61a5..497c1eea 100644 --- a/internal/tuple/import.go +++ b/internal/tuple/import.go @@ -120,6 +120,10 @@ func ImportTuples(ctx context.Context, fgaClient client.SdkClient, MaxPerChunk: maxTuplesPerWrite32, MaxParallelRequests: maxParallelRequests32, }, + Conflict: client.ClientWriteConflictOptions{ + OnDuplicateWrites: client.CLIENT_WRITE_REQUEST_ON_DUPLICATE_WRITES_IGNORE, + OnMissingDeletes: client.CLIENT_WRITE_REQUEST_ON_MISSING_DELETES_ERROR, + }, } // If RPS values are 0, then fallback to the previous way of importing From 108d82243734fe8e5ada37e0b1a04289605a608b Mon Sep 17 00:00:00 2001 From: Raghd Hamzeh Date: Wed, 8 Oct 2025 17:44:02 -0400 Subject: [PATCH 2/2] chore: fix extraneous deletes option in import to be ignore instead of error --- internal/tuple/import.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/tuple/import.go b/internal/tuple/import.go index 497c1eea..807d5022 100644 --- a/internal/tuple/import.go +++ b/internal/tuple/import.go @@ -122,7 +122,7 @@ func ImportTuples(ctx context.Context, fgaClient client.SdkClient, }, Conflict: client.ClientWriteConflictOptions{ OnDuplicateWrites: client.CLIENT_WRITE_REQUEST_ON_DUPLICATE_WRITES_IGNORE, - OnMissingDeletes: client.CLIENT_WRITE_REQUEST_ON_MISSING_DELETES_ERROR, + OnMissingDeletes: client.CLIENT_WRITE_REQUEST_ON_MISSING_DELETES_IGNORE, }, }