-
Notifications
You must be signed in to change notification settings - Fork 88
feat: Add string-based namespace support in Txns #262
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
base: main
Are you sure you want to change the base?
feat: Add string-based namespace support in Txns #262
Conversation
Add tests; update test docker compose file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds string‐based namespace support to transactions in the Txn class to simplify manual transaction management with the dgo client.
- Introduces NewTxnInNamespace and NewReadOnlyTxnInNamespace methods in txn.go.
- Adds comprehensive tests in v2_test.go and examples_test.go to verify namespace behavior.
- Updates docker-compose.yml to include non‐ACL service configurations for testing.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
v2_test.go | Adds tests for namespace creation, duplicate namespace error handling, and Txn usage. |
txn.go | Introduces new namespace field and helper methods for namespace-aware transactions. |
t/docker-compose.yml | Provides new docker services for a non‑ACL environment to support testing. |
examples_test.go | Adds functions to obtain dgo clients in non‑ACL mode and tests namespace support. |
Comments suppressed due to low confidence (1)
txn.go:67
- Correct the abbreviation 'Tnx' to 'Txn' for clarity in the comment.
// in the default namespace. Note that a Tnx created with this function will not complete successfully as the
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
c7159b5
to
3f812cf
Compare
I think this would be a great improvement. With the V2 apis, namespaces are simple and a separate concept from ACL/auth, which is fantastic and exactly what I need. We have some graphs that update continuously, and others that are a monthly dump to be dropped and recreated in full. Namespaces gives me an easy way to acheive this data separation. I do not need different auth rules and user separation across the namespaces, as they are purely used by a single backend service. The missing parts are to enable namespace selection everywhere, without requiring different logins. So dgo transactions, graphQL admin requests (upload schema etc), graphQL queries and the Ratel/play UI. Happy to add additional info if it helps! See https://discuss.hypermode.com/t/v25-multitenency/19915/3 |
Now that I understand that apiv2 currently deprecates json-based mutatations this change is very important, as I can fall back to legacy apis for these, provided I have a way to set namespaces, which this PR provides. |
txn.go
Outdated
// in the default namespace. Note that a Tnx created with this function | ||
// against an ACL-enabled Dgraph cluster will not complete successfully as the | ||
// namespace from the JWT is used to calculate the namespace ID. | ||
func (d *Dgraph) NewTxnInNamespace(namespace string) *Txn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how we should structure the API now:
- NewTxn(): existing function, should create a txn in the root namespace
- NewReadOnlyTxn(): existing function, should create a read only txn in root namespace
- NewTxnInNamespace(): txn in a given namespace
- NewReadOnlyTxnInNamespace(): read only txn in a given namespace
OR
- NewTxn(TxnOptions)
- NewReadOnlyTxn(): will deprecate this later
here, TxnOptions could be BestEffort, ReadOnly and provide namespace as well. We should update existing v2 APIs to take namespace as a TxnOption as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. The second way is cleaner. I added a WithNamespace to TxnOption
s. So it looks like:
txn := client.NewTxn(dgo.WithNamespace("foo"), dgo.WithReadOnly())
I wonder now if the namespace arg in the v2 funcs is needed
Currently...
resp, err = client.RunDQL(ctx, dgo.RootNamespace, queryDQL, dgo.WithBestEffort())
Could be changed to:
resp, err = client.RunDQL(ctx, queryDQL, dgo.WithNamespace(dgo.RootNamespace), dgo.WithBestEffort())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aman-bansal I can make the changes to all the v2 APIs in this PR (removing the namespace attribute, replacing with the WithNamespace
TxnOption). Just let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewmcneely Yes please go ahead with it.
dff703b
to
6f13f7f
Compare
502133e
to
db0cbbd
Compare
db0cbbd
to
2bc5582
Compare
Description
This PR adds string-based namespace support to the Txn class. Managing transactions manually is something common in many repos that use the dgo client. This new functionality makes upgrading transaction-heavy code (that wants to use string-based namespaces) less cumbersome.
Note that the v2
TestTxNamespaces
will fail until Dgraph PR hypermodeinc/dgraph#9433 is merged.Checklist
CHANGELOG.md
file describing and linking tothis PR