When passing an empty array to update_fields, Chewy performs a full document reindex instead of treating it as a no-op (no fields to update). This is unexpected and dangerous behavior.
Expected Behavior
update_fields: [] should mean "update zero fields" - i.e., do nothing or skip the update. An empty array is an explicit empty set.
If "update all fields" is intended, it should be triggered by update_fields: nil or by omitting the option entirely.
Actual Behavior
update_fields: [] triggers a full document replacement, overwriting all fields with current model values.
Why This Is Problematic
Consider a pipeline that updates different transient (so I don't store fields in AR, they re simple attribute accessors) field groups:
DocumentIndex.import(
[document],
direct_import: true,
update_fields: document.class.transient_attributes(fields_group) # --> []
)
end
This is a silent data loss bug that's very hard to debug.
When passing an empty array to
update_fields, Chewy performs a full document reindex instead of treating it as a no-op (no fields to update). This is unexpected and dangerous behavior.Expected Behavior
update_fields: []should mean "update zero fields" - i.e., do nothing or skip the update. An empty array is an explicit empty set.If "update all fields" is intended, it should be triggered by
update_fields: nilor by omitting the option entirely.Actual Behavior
update_fields: []triggers a full document replacement, overwriting all fields with current model values.Why This Is Problematic
Consider a pipeline that updates different transient (so I don't store fields in AR, they re simple attribute accessors) field groups:
This is a silent data loss bug that's very hard to debug.