From 22350d38bcc8c5252c10ce7fa759677ae6b372b8 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:53:47 +1000 Subject: [PATCH] Filter migration fix (#4151) * 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 --- pkg/sqlite/migrations/49_postmigrate.go | 44 +++++++++++-------- .../models/list-filter/criteria/criterion.ts | 5 ++- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pkg/sqlite/migrations/49_postmigrate.go b/pkg/sqlite/migrations/49_postmigrate.go index 941cf6a8802..c39bc5f3191 100644 --- a/pkg/sqlite/migrations/49_postmigrate.go +++ b/pkg/sqlite/migrations/49_postmigrate.go @@ -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) @@ -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) + } } } diff --git a/ui/v2.5/src/models/list-filter/criteria/criterion.ts b/ui/v2.5/src/models/list-filter/criteria/criterion.ts index 6b2b79ac2e1..c6bc8a4c5f8 100644 --- a/ui/v2.5/src/models/list-filter/criteria/criterion.ts +++ b/ui/v2.5/src/models/list-filter/criteria/criterion.ts @@ -143,7 +143,10 @@ export abstract class Criterion { } public setFromEncodedCriterion(encodedCriterion: IEncodedCriterion) { - if (encodedCriterion.value !== undefined) { + if ( + encodedCriterion.value !== undefined && + encodedCriterion.value !== null + ) { this.value = encodedCriterion.value; } this.modifier = encodedCriterion.modifier;