-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4945: Fix default sync function dry run #7937
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
Conversation
bbrks
left a comment
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 only works for the default collection
db/crud.go
Outdated
| } | ||
| } else { | ||
| if syncFn == "" { | ||
| syncFn = channels.DocChannelsSyncFunction |
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 only the default sync function for the default collection. Named collections have a slightly different default sync function.
I'd probably use the GetDefaultSyncFunction function instead and pull out the scope/collection name from db *DatabaseCollectionWithUser
For reference: The code inside getChannelsAndAccess is doing the job of "faking" a sync function when ChannelMapper is nil, by looking at specific properties in the doc body (around lines 3331-3344)
https://github.com/couchbase/sync_gateway/blob/main/db/crud.go#L3332-L3344
9a64b63 to
52ec132
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 fixes the behavior of the sync function dry run feature when using the default sync function in Sync Gateway. Previously, when no custom sync function was provided, the dry run would fail to properly apply the default sync function for the collection.
Key changes:
- Modified the conditional logic in
SyncFnDryrunto properly handle cases where no custom sync function is defined - Added test cases to verify the default sync function behavior in dry run scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| db/crud.go | Updated SyncFnDryrun method to correctly apply the default sync function when no custom sync function is provided |
| rest/diagnostic_doc_api_test.go | Added two new test cases to verify dry run behavior with the default sync function for both new and existing documents |
rest/diagnostic_doc_api_test.go
Outdated
| // Since the tests run in named Scopes and Collections therefore the | ||
| // default sync function is: | ||
| // function(doc){channel("<collection_name>");} | ||
| // therefore the channels returned will be named collections |
Copilot
AI
Dec 24, 2025
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.
The phrase 'therefore the' appears twice in succession. The comment should be restructured for better readability. Consider: 'Since the tests run in named Scopes and Collections, the default sync function is: function(doc){channel("<collection_name>");}. Therefore, the channels returned will be named collections.'
| // Since the tests run in named Scopes and Collections therefore the | |
| // default sync function is: | |
| // function(doc){channel("<collection_name>");} | |
| // therefore the channels returned will be named collections | |
| // Since the tests run in named Scopes and Collections, the default sync function is: | |
| // function(doc){channel("<collection_name>");}. Therefore, the channels returned will be named collections. |
| var output *channels.ChannelMapperOutput | ||
| var syncErr error | ||
| if syncFn == "" { | ||
| if syncFn == "" && db.ChannelMapper != nil { |
Copilot
AI
Dec 24, 2025
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.
The logic flow has become less clear with the nested conditions. The outer condition checks syncFn == \"\" twice in different branches. Consider restructuring to: first check if syncFn is empty and set it to the default if needed, then proceed with a single conditional based on whether to use ChannelMapper or SyncRunner.
CBG-4945
Describe your PR here...
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests
GSI=true,xattrs=truehttps://jenkins.sgwdev.com/job/SyncGatewayIntegration/206/