fix: stop three recurring errors on doc delete (#17685) (#17686)

Follow-up to #17526 ("Refactor: merge dataset scope graph"), which introduced two code paths that touch Infinity columns the deployed schema does not declare. This PR makes the runtime robust against the old schema while also adding the new column to the new schema so freshly created tables are correct.
This commit is contained in:
S
2026-08-16 06:55:51 +05:30
committed by GitHub
parent 554fb1133a
commit c6ba54bc72
14 changed files with 1140 additions and 35 deletions

View File

@@ -885,6 +885,9 @@ func (e *Engine) DeleteChunks(ctx context.Context, condition map[string]interfac
// Build the query
var qry map[string]interface{}
if len(filterClauses) == 0 && len(mustClauses) == 0 && len(mustNotClauses) == 0 {
if len(condition) > 0 {
return 0, fmt.Errorf("ES delete aborted: non-empty condition yielded match_all query on index %s", fullIndexName)
}
qry = map[string]interface{}{"match_all": map[string]interface{}{}}
} else {
boolMap := map[string]interface{}{}

View File

@@ -686,6 +686,10 @@ func (e *Engine) DeleteChunks(ctx context.Context, condition map[string]interfac
// Build filter from condition
filter := buildFilterFromCondition(condition, clmns)
if len(condition) > 0 && (filter == "" || filter == "1=1") {
return 0, fmt.Errorf("INFINITY delete aborted: non-empty condition yielded unconstrained filter on table %s", tableName)
}
delResp, err := table.Delete(filter)
if err != nil {
return 0, fmt.Errorf("failed to delete: %w", err)

View File

@@ -386,6 +386,10 @@ func (e *Engine) deleteMetadataWithTable(table *infinity.Table, condition map[st
// Build filter from condition
filter := buildFilterFromCondition(condition, clmns)
if len(condition) > 0 && (filter == "" || filter == "1=1") {
return 0, fmt.Errorf("INFINITY delete aborted: non-empty condition yielded unconstrained filter")
}
delResp, err := table.Delete(filter)
if err != nil {
return 0, fmt.Errorf("failed to delete metadata: %w", err)

View File

@@ -379,3 +379,24 @@ func TestLoadFieldMapping_EmptyNameDefaultsToInfinityMappingJSON(t *testing.T) {
t.Errorf("empty name + no file should yield empty maps; got a2a=%v r2a=%v", a2a, r2a)
}
}
func TestBuildFilterFromCondition_UnconstrainedFilter(t *testing.T) {
clmns := map[string]struct {
Type string
Default interface{}
}{
"id": {"Varchar", ""},
}
// empty condition yields "1=1"
if got := buildFilterFromCondition(map[string]interface{}{}, clmns); got != "1=1" {
t.Errorf("empty condition: got %q, want '1=1'", got)
}
// condition with nil or empty string values yields "1=1"
cond := map[string]interface{}{
"source_id": "",
"nil_field": nil,
}
if got := buildFilterFromCondition(cond, clmns); got != "1=1" {
t.Errorf("non-empty condition with blank values: got %q, want '1=1'", got)
}
}