Repository navigation
feat[Go]: implement /api/v1/connectors/<connector_id> PATCH - #15512
Conversation
📝 WalkthroughWalkthroughThis PR adds connector update functionality with optional task rescheduling across the DAO, service, and handler layers. The DAO provides task scheduling helpers; the service implements update logic with partial field support and conditional task rescheduling; the handler exposes an HTTP endpoint to trigger updates. ChangesConnector Update with Task Rescheduling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/dao/connector.go (1)
304-318: ⚡ Quick winReuse
connectorConfigBoolinRebuildConnectorfor consistent config parsing.
ScheduleConnectorTasksinterpretssync_deleted_filesvia this helper (handles bool and"1"/"true"/"TRUE"), whileRebuildConnectorat Line 225 still uses a bareconnector.Config["sync_deleted_files"].(bool). A config persisted as a string would schedule a prune task in one path but not the other. Consider routing both throughconnectorConfigBool.♻️ Proposed change at Line 225
- if syncDeletedFiles, _ := connector.Config["sync_deleted_files"].(bool); syncDeletedFiles { + if connectorConfigBool(connector.Config, "sync_deleted_files") {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/dao/connector.go` around lines 304 - 318, Rework RebuildConnector to use the existing connectorConfigBool helper for parsing sync_deleted_files instead of the direct type assertion connector.Config["sync_deleted_files"].(bool); locate the branch in RebuildConnector where it currently reads that config (the bare type assertion) and replace it with a call like connectorConfigBool(connector.Config, "sync_deleted_files") so parsing of bools and string representations ("1"/"true"/"TRUE") is consistent with ScheduleConnectorTasks.internal/handler/connector_test.go (1)
48-53: ⚡ Quick winAdd a handler test for the new
UpdateConnectorendpoint.The fake gains an
UpdateConnectormethod to satisfy the interface, but no test (e.g.TestConnectorHandlerUpdateConnector) exercises the new handler/decoder path including the nesteddataobject handling and success/error code mapping. Adding coverage parallel to the existingDelete/ListLogstests would protect the new endpoint.Want me to draft a
TestConnectorHandlerUpdateConnectorcovering success, not-found, and unauthorized cases plus the nesteddatapayload?🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/connector_test.go` around lines 48 - 53, Add a new table-driven test named TestConnectorHandlerUpdateConnector that exercises the handler and decoder path for the new UpdateConnector endpoint: call the HTTP handler that routes to ConnectorHandler.UpdateConnector (or equivalent) and use the request decoder (e.g., decodeUpdateConnectorRequest) to verify nested "data" JSON is parsed into service.UpdateConnectorRequest correctly; mock responses via the fakeConnectorService.UpdateConnector to cover success (returning *entity.Connector and common.CodeSuccess), not-found (returning nil and common.CodeNotFound), and unauthorized (returning nil and common.CodeUnauthorized) cases, and assert HTTP status codes and response bodies mirror the existing Delete/ListLogs tests' assertions for success/error mapping. Ensure the test constructs the nested data payload, wires the fakeConnectorService into the handler, and checks both decoded request contents and mapped HTTP responses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/dao/connector.go`:
- Around line 272-282: The query that finds the latest completed SyncLogs uses
Order("update_time DESC") which may reference a non-existent column (compare
with ListLogsByConnectorID which orders by update_date); update this to use the
actual timestamp column name defined on entity.SyncLogs (e.g., "update_date" or
the BaseModel field name) so the First(&latest) call doesn't fail silently, and
ensure pollRangeStart is assigned from latest.PollRangeEnd and totalDocsIndexed
from latest.TotalDocsIndexed only after the corrected query (symbols: SyncLogs,
ListLogsByConnectorID, update_time/update_date, pollRangeStart, PollRangeEnd,
totalDocsIndexed).
---
Nitpick comments:
In `@internal/dao/connector.go`:
- Around line 304-318: Rework RebuildConnector to use the existing
connectorConfigBool helper for parsing sync_deleted_files instead of the direct
type assertion connector.Config["sync_deleted_files"].(bool); locate the branch
in RebuildConnector where it currently reads that config (the bare type
assertion) and replace it with a call like connectorConfigBool(connector.Config,
"sync_deleted_files") so parsing of bools and string representations
("1"/"true"/"TRUE") is consistent with ScheduleConnectorTasks.
In `@internal/handler/connector_test.go`:
- Around line 48-53: Add a new table-driven test named
TestConnectorHandlerUpdateConnector that exercises the handler and decoder path
for the new UpdateConnector endpoint: call the HTTP handler that routes to
ConnectorHandler.UpdateConnector (or equivalent) and use the request decoder
(e.g., decodeUpdateConnectorRequest) to verify nested "data" JSON is parsed into
service.UpdateConnectorRequest correctly; mock responses via the
fakeConnectorService.UpdateConnector to cover success (returning
*entity.Connector and common.CodeSuccess), not-found (returning nil and
common.CodeNotFound), and unauthorized (returning nil and
common.CodeUnauthorized) cases, and assert HTTP status codes and response bodies
mirror the existing Delete/ListLogs tests' assertions for success/error mapping.
Ensure the test constructs the nested data payload, wires the
fakeConnectorService into the handler, and checks both decoded request contents
and mapped HTTP responses.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6bd1218f-624b-40b3-8f7e-b57d2c20ed35
📒 Files selected for processing (4)
internal/dao/connector.gointernal/handler/connector.gointernal/handler/connector_test.gointernal/service/connector.go
| var latest entity.SyncLogs | ||
| err := tx.Where("connector_id = ? AND kb_id = ? AND task_type = ? AND status = ?", connectorID, kbID, taskType, string(entity.TaskStatusDone)). | ||
| Order("update_time DESC"). | ||
| First(&latest).Error | ||
| if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { | ||
| return err | ||
| } | ||
| if err == nil { | ||
| pollRangeStart = latest.PollRangeEnd | ||
| totalDocsIndexed = latest.TotalDocsIndexed | ||
| } |
There was a problem hiding this comment.
Verify the update_time column used for ordering the latest completed log.
This query orders by update_time DESC, but the existing ListLogsByConnectorID query (Line 353) orders SyncLogs by update_date. If update_time is not a real column on the sync_logs table, this First(...) call will error (and only gorm.ErrRecordNotFound is tolerated). Please confirm the column exists; otherwise the "resume from last completed poll" logic silently breaks the schedule.
#!/bin/bash
# Find BaseModel/SyncLogs column definitions to confirm update_time exists
ast-grep --pattern 'type BaseModel struct {
$$$
}'
echo "----- update_time / update_date references on sync logs -----"
rg -nP "update_(time|date)" --type=go -C2🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/dao/connector.go` around lines 272 - 282, The query that finds the
latest completed SyncLogs uses Order("update_time DESC") which may reference a
non-existent column (compare with ListLogsByConnectorID which orders by
update_date); update this to use the actual timestamp column name defined on
entity.SyncLogs (e.g., "update_date" or the BaseModel field name) so the
First(&latest) call doesn't fail silently, and ensure pollRangeStart is assigned
from latest.PollRangeEnd and totalDocsIndexed from latest.TotalDocsIndexed only
after the corrected query (symbols: SyncLogs, ListLogsByConnectorID,
update_time/update_date, pollRangeStart, PollRangeEnd, totalDocsIndexed).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15512 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? As title /api/v1/connectors/<connector_id> PATCH was implemented in #15512 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Refactoring
What problem does this PR solve?
As title, all test are passed
Type of change