Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter migration fix #4151

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading