Skip to content

Commit

Permalink
Filter migration fix (#4151)
Browse files Browse the repository at this point in the history
* Exclude value for is null/not null

Also includes changes to the error message in the migration to include the filter string.

* Ignore null when setting from encoded criterion
  • Loading branch information
WithoutPants authored Sep 25, 2023
1 parent 9f5bcca commit 22350d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
44 changes: 25 additions & 19 deletions pkg/sqlite/migrations/49_postmigrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ func (m *schema49Migrator) migrateSavedFilters(ctx context.Context) error {

newFindFilter, err := m.getFindFilter(asRawMessage)
if err != nil {
return fmt.Errorf("failed to get find filter for saved filter %d: %w", id, err)
return fmt.Errorf("failed to get find filter for saved filter %s : %w", findFilter, err)
}

objectFilter, err := m.getObjectFilter(mode, asRawMessage)
if err != nil {
return fmt.Errorf("failed to get object filter for saved filter %d: %w", id, err)
return fmt.Errorf("failed to get object filter for saved filter %s : %w", findFilter, err)
}

uiOptions, err := m.getDisplayOptions(asRawMessage)
if err != nil {
return fmt.Errorf("failed to get display options for saved filter %d: %w", id, err)
return fmt.Errorf("failed to get display options for saved filter %s : %w", findFilter, err)
}

_, err = m.db.Exec("UPDATE saved_filters SET find_filter = ?, object_filter = ?, ui_options = ? WHERE id = ?", newFindFilter, objectFilter, uiOptions, id)
Expand Down Expand Up @@ -252,23 +252,29 @@ func (m *schema49Migrator) convertCriterion(mode models.FilterMode, out map[stri
}
delete(ret, "type")

// Find out whether the object needs some adjustment/has non-string content attached
// Only adjust if value is present
if v, ok := ret["value"]; ok && v != nil {
var err error
switch {
case arrayContains(migrate49TypeResolution["Boolean"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "bool")
case arrayContains(migrate49TypeResolution["Int"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "int")
case arrayContains(migrate49TypeResolution["Float"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "float64")
case arrayContains(migrate49TypeResolution["Object"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "object")
}
// unset the value for IS_NULL or NOT_NULL modifiers
modifier := models.CriterionModifier(ret["modifier"].(string))
if modifier == models.CriterionModifierIsNull || modifier == models.CriterionModifierNotNull {
delete(ret, "value")
} else {
// Find out whether the object needs some adjustment/has non-string content attached
// Only adjust if value is present
if v, ok := ret["value"]; ok && v != nil {
var err error
switch {
case arrayContains(migrate49TypeResolution["Boolean"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "bool")
case arrayContains(migrate49TypeResolution["Int"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "int")
case arrayContains(migrate49TypeResolution["Float"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "float64")
case arrayContains(migrate49TypeResolution["Object"], field):
ret["value"], err = m.adjustCriterionValue(ret["value"], "object")
}

if err != nil {
return fmt.Errorf("failed to adjust criterion value for %q: %w", field, err)
if err != nil {
return fmt.Errorf("failed to adjust criterion value for %q: %w", field, err)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion ui/v2.5/src/models/list-filter/criteria/criterion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export abstract class Criterion<V extends CriterionValue> {
}

public setFromEncodedCriterion(encodedCriterion: IEncodedCriterion<V>) {
if (encodedCriterion.value !== undefined) {
if (
encodedCriterion.value !== undefined &&
encodedCriterion.value !== null
) {
this.value = encodedCriterion.value;
}
this.modifier = encodedCriterion.modifier;
Expand Down

0 comments on commit 22350d3

Please sign in to comment.