Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that a new Gorm instance is created when applying a context, rather than modifying the original instance directly. Key changes include:
- Updating mocks to reflect a return value for the context function.
- Introducing a new QueryWithContext mock that implements the WithContext method.
- Replacing the SetContext method with the WithContext method in the production code and contracts.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| mocks/database/orm/QueryWithSetContext.go | Updated SetContext to return orm.Query; may need renaming for consistency |
| mocks/database/orm/QueryWithContext.go | Added a new mock for WithContext to support the new interface |
| database/orm/orm.go | Modified Query() to use the WithContext method based on the context |
| database/gorm/query.go | Replaced SetContext with WithContext creating a new Query instance |
| contracts/database/orm/orm.go | Updated the interface from QueryWithSetContext to QueryWithContext |
Comments suppressed due to low confidence (2)
mocks/database/orm/QueryWithSetContext.go:26
- Consider renaming the 'SetContext' method to 'WithContext' to match the updated interface in contracts (QueryWithContext) or remove this outdated mock if it is no longer used.
func (_m *QueryWithSetContext) SetContext(ctx context.Context) orm.Query {
database/orm/orm.go:128
- Directly comparing r.ctx to context.Background() may not reliably determine if a custom context is set; consider a more robust check or clear documentation on why this comparison is sufficient.
if r.ctx != context.Background() {
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #978 +/- ##
=======================================
Coverage 69.10% 69.10%
=======================================
Files 168 168
Lines 11340 11340
=======================================
Hits 7836 7836
Misses 3152 3152
Partials 352 352 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📑 Description
The Gorm instance should not be modified directly, we need to call the
WithContextfunction to get a new Gorm instance to avoid concurrence.✅ Checks