-
Notifications
You must be signed in to change notification settings - Fork 95
* Added validation of WithTxControl option in non-interactive methods… #1738
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: master
Are you sure you want to change the base?
Conversation
… of Client and Session
summaryBase version: v3.108.1 (master) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1738 +/- ##
==========================================
- Coverage 71.20% 70.98% -0.23%
==========================================
Files 383 384 +1
Lines 39152 39212 +60
==========================================
- Hits 27878 27833 -45
- Misses 10148 10230 +82
- Partials 1126 1149 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
3f3d26d
to
813e20e
Compare
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 validation for the WithTxControl option in non‑interactive Client and Session methods to ensure that a proper commit flag accompanies the transaction control setting. Key changes include:
- Updating tests to use SnapshotReadOnlyTxControl instead of SerializableReadWriteTxControl.
- Adding a new check (checkTxControlWithCommit) in Session and Client methods.
- Adjusting error handling and documentation for the newly added validation.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tests/integration/query_regression_test.go | Updated tests to use SnapshotReadOnlyTxControl for transaction control validation. |
internal/xreflect/is_nil.go & is_nil_test.go | Added utility function and tests for nil pointer inspection used in transaction control logic. |
internal/query/session.go | Updated non‑interactive methods to call checkTxControlWithCommit before executing queries/exec. |
internal/query/client.go | Implemented checkTxControlWithCommit validation and updated error handling for WithTxControl. |
examples/basic/native/query/series.go | Updated example usage to apply SnapshotReadOnlyTxControl. |
CHANGELOG.md | Documented the added validation behavior and changes to transaction control options. |
internal/query/client.go
Outdated
@@ -612,6 +638,15 @@ func New(ctx context.Context, cc grpc.ClientConnInterface, cfg *config.Config) * | |||
} | |||
} | |||
|
|||
// checkTxControlWithCommit checks that if WithTxControl is used, it must be with WithCommit |
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.
Consider adding a detailed docstring for checkTxControlWithCommit to explain why non‑interactive methods require a commit flag and how txControl is validated.
// checkTxControlWithCommit checks that if WithTxControl is used, it must be with WithCommit | |
// checkTxControlWithCommit validates the transaction control object to ensure it includes a commit flag. | |
// | |
// Non-interactive methods require a commit flag because they execute operations that must be finalized | |
// to ensure data consistency and durability. Without the commit flag, the transaction would remain | |
// incomplete, potentially leading to undefined behavior or data loss. | |
// | |
// This function checks if the provided txControl object is non-nil and whether the Commit() method | |
// returns true. If the commit flag is missing, an error is returned to indicate that the transaction | |
// control is invalid for the intended operation. |
Copilot uses AI. Check for mistakes.
@@ -32,6 +34,8 @@ var ( | |||
_ sessionPool = (*pool.Pool[*Session, Session])(nil) | |||
) | |||
|
|||
var errNoCommit = xerrors.Wrap(errors.New("WithTxControl option is not allowed without CommitTx() option in Client methods, as these methods are non-interactive. You can either add the CommitTx() option to TxControl or use query.*TxControl methods (e.g., query.SnapshotReadOnlyTxControl) which already include the commit flag")) //nolint:lll |
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.
Consider splitting the error message or adding inline comments to clarify the error rationale for future maintainers.
var errNoCommit = xerrors.Wrap(errors.New("WithTxControl option is not allowed without CommitTx() option in Client methods, as these methods are non-interactive. You can either add the CommitTx() option to TxControl or use query.*TxControl methods (e.g., query.SnapshotReadOnlyTxControl) which already include the commit flag")) //nolint:lll | |
// errNoCommit is raised when the WithTxControl option is used without the CommitTx() option. | |
// This is because Client methods are non-interactive and require explicit commit control. | |
// To resolve this, either add the CommitTx() option to TxControl or use query.*TxControl methods | |
// (e.g., query.SnapshotReadOnlyTxControl) that already include the commit flag. | |
var errNoCommit = xerrors.Wrap(errors.New("WithTxControl option is not allowed without CommitTx() option in Client methods.")) | |
var errNoCommitResolution = xerrors.Wrap(errors.New("You can either add the CommitTx() option to TxControl or use query.*TxControl methods (e.g., query.SnapshotReadOnlyTxControl) which already include the commit flag")) //nolint:lll |
Copilot uses AI. Check for mistakes.
@@ -25,7 +25,7 @@ func read(ctx context.Context, c query.Client, prefix string) error { | |||
FROM | |||
%s | |||
`, "`"+path.Join(prefix, "series")+"`"), | |||
query.WithTxControl(query.TxControl(query.BeginTx(query.WithSnapshotReadOnly()))), | |||
query.WithTxControl(query.SnapshotReadOnlyTxControl()), |
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.
Pay attention to the line. I have changed the txcontrol in the example.
@@ -45,7 +45,7 @@ DECLARE $val AS UUID; | |||
SELECT CAST($val AS Utf8)`, | |||
query.WithIdempotent(), | |||
query.WithParameters(ydb.ParamsBuilder().Param("$val").UUIDWithIssue1501Value(id).Build()), | |||
query.WithTxControl(tx.SerializableReadWriteTxControl()), | |||
query.WithTxControl(tx.SnapshotReadOnlyTxControl()), |
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.
Pay attention to the changes. I have changed txControl in tests
@@ -38,9 +38,9 @@ func TestDatabaseSqlWithTxControl(t *testing.T) { | |||
ydb.WithTxControl( | |||
tx.WithTxControlHook(ctx, func(txControl *tx.Control) { | |||
hookCalled = true | |||
require.Equal(t, tx.SerializableReadWriteTxControl(), txControl) | |||
require.Equal(t, tx.SerializableReadWriteTxControl(tx.CommitTx()), txControl) |
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.
I have added an explicit CommitTx to the test.
CHANGELOG.md
Outdated
@@ -1,3 +1,6 @@ | |||
* Added validation of WithTxControl option in non-interactive methods of Client and Session | |||
|
|||
======= |
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.
А это зачем?
… of Client and Session
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Other information