From 782bed9df882b6be2daf05d7f1191d64de77a891 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Tue, 6 Dec 2022 13:33:58 +1100 Subject: [PATCH] Fix date fields not being nulled correctly when cleared (#3243) * Interpret empty string date as null * Fix setSQLiteDate for null --- internal/api/changeset_translator.go | 2 +- pkg/sqlite/record.go | 10 +++++----- ui/v2.5/src/docs/en/Changelog/v0190.md | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/api/changeset_translator.go b/internal/api/changeset_translator.go index 3e768a136..ff182ed32 100644 --- a/internal/api/changeset_translator.go +++ b/internal/api/changeset_translator.go @@ -143,7 +143,7 @@ func (t changesetTranslator) optionalDate(value *string, field string) models.Op return models.OptionalDate{} } - if value == nil { + if value == nil || *value == "" { return models.OptionalDate{ Set: true, Null: true, diff --git a/pkg/sqlite/record.go b/pkg/sqlite/record.go index 9c6938c5d..fbee73e86 100644 --- a/pkg/sqlite/record.go +++ b/pkg/sqlite/record.go @@ -102,11 +102,11 @@ func (r *updateRecord) setSQLiteDate(destField string, v models.OptionalDate) { if v.Set { if v.Null { r.set(destField, models.SQLiteDate{}) + } else { + r.set(destField, models.SQLiteDate{ + String: v.Value.String(), + Valid: true, + }) } - - r.set(destField, models.SQLiteDate{ - String: v.Value.String(), - Valid: true, - }) } } diff --git a/ui/v2.5/src/docs/en/Changelog/v0190.md b/ui/v2.5/src/docs/en/Changelog/v0190.md index de20c2936..9a956bf69 100644 --- a/ui/v2.5/src/docs/en/Changelog/v0190.md +++ b/ui/v2.5/src/docs/en/Changelog/v0190.md @@ -9,6 +9,7 @@ * Changed performer aliases to be a list, rather than a string field. ([#3113](https://github.com/stashapp/stash/pull/3113)) ### 🐛 Bug fixes +* Fixed date fields not being nulled correctly when cleared. ([#3243](https://github.com/stashapp/stash/pull/3243)) * Fixed scene wall items to show file base name where scene has no title set. ([#3242](https://github.com/stashapp/stash/pull/3242)) * Fixed image exclusion pattern being applied to all files. ([#3241](https://github.com/stashapp/stash/pull/3241)) * Fixed missing captions not being removed during scan. ([#3240](https://github.com/stashapp/stash/pull/3240)) \ No newline at end of file