Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(datasource): restore sync_deletions on the in-memory object after create
wizardchen412dcc41c662
diff --git a/internal/application/repository/datasource_repo.go b/internal/application/repository/datasource_repo.goindex 3cf70eb13..c3b2f58e4 100644--- a/internal/application/repository/datasource_repo.go+++ b/internal/application/repository/datasource_repo.go@@ -25,10 +25,13 @@ func (r *DataSourceRepository) Create(ctx context.Context, ds *types.DataSource)if ds == nil {return errors.New("data source is nil")}- // GORM may omit a false value for a field with a database default. Preserve- // the caller's choice before Create potentially hydrates that default.+ // GORM treats false as the zero value of bool. For a field tagged+ // default:true it replaces both the INSERT value and the in-memory field+ // with true, so a caller-selected false would be lost. Capture it, force+ // the column write, then restore the struct so Create's return value (and+ // the HTTP 201 body) match the database.syncDeletions := ds.SyncDeletions- return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {+ err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {if err := tx.Create(ds).Error; err != nil {return err}@@ -36,6 +39,8 @@ func (r *DataSourceRepository) Create(ctx context.Context, ds *types.DataSource)Where("id = ?", ds.ID).UpdateColumn("sync_deletions", syncDeletions).Error})+ ds.SyncDeletions = syncDeletions+ return err}// FindByID retrieves a data source by IDdiff --git a/internal/application/repository/datasource_repo_test.go b/internal/application/repository/datasource_repo_test.goindex e430fa0e3..77ed065c3 100644--- a/internal/application/repository/datasource_repo_test.go+++ b/internal/application/repository/datasource_repo_test.go@@ -68,10 +68,17 @@ func TestDataSourceRepositoryUpdatePersistsDisabledSyncDeletions(t *testing.T) {ds.SyncDeletions = falserequire.NoError(t, repo.Update(ctx, ds))+ assert.False(t, ds.SyncDeletions)var stored types.DataSourcerequire.NoError(t, db.First(&stored, "id = ?", ds.ID).Error)assert.False(t, stored.SyncDeletions)++ ds.SyncDeletions = true+ require.NoError(t, repo.Update(ctx, ds))+ assert.True(t, ds.SyncDeletions)+ require.NoError(t, db.First(&stored, "id = ?", ds.ID).Error)+ assert.True(t, stored.SyncDeletions)}func TestDataSourceRepositoryCreatePersistsDisabledSyncDeletions(t *testing.T) {@@ -88,10 +95,39 @@ func TestDataSourceRepositoryCreatePersistsDisabledSyncDeletions(t *testing.T) {SyncDeletions: false,}require.NoError(t, repo.Create(ctx, ds))+ assert.False(t, ds.SyncDeletions, "Create must not leave the in-memory field hydrated to the GORM default")var stored types.DataSourcerequire.NoError(t, db.First(&stored, "id = ?", ds.ID).Error)assert.False(t, stored.SyncDeletions)++ // A later Updates() on the same pointer must not persist the hydrated default.+ ds.Name = "Renamed"+ require.NoError(t, repo.Update(ctx, ds))+ require.NoError(t, db.First(&stored, "id = ?", ds.ID).Error)+ assert.False(t, stored.SyncDeletions)+ assert.Equal(t, "Renamed", stored.Name)+}++func TestDataSourceRepositoryCreatePersistsEnabledSyncDeletions(t *testing.T) {+ db := setupDataSourceRepoTestDB(t)+ repo := NewDataSourceRepository(db)+ ctx := context.Background()++ ds := &types.DataSource{+ ID: "ds-create-sync-deletions-enabled",+ TenantID: 1,+ KnowledgeBaseID: "kb-1",+ Name: "Feishu",+ Type: types.ConnectorTypeFeishu,+ SyncDeletions: true,+ }+ require.NoError(t, repo.Create(ctx, ds))+ assert.True(t, ds.SyncDeletions)++ var stored types.DataSource+ require.NoError(t, db.First(&stored, "id = ?", ds.ID).Error)+ assert.True(t, stored.SyncDeletions)}func TestDataSourceRepositoryDeleteSoftDeletesOnSQLite(t *testing.T) {