From 7110a1fab30e59fa686b0f102fd73a5702d417a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 20 Apr 2024 11:49:37 +0200 Subject: [PATCH] Fix failing tests for decodeNil() Fix https://github.com/groue/GRDB.swift/issues/1531 --- GRDB/Record/FetchableRecord+Decodable.swift | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index fc2e14fd4..907192292 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -175,15 +175,25 @@ private struct _RowDecoder: Decoder { func decodeNil(forKey key: Key) throws -> Bool { let row = decoder.row - if let column = try? decodeColumn(forKey: key), row[column] != nil { - return false - } - if row.scopesTree[key.stringValue] != nil { - return false - } - if row.prefetchedRows[key.stringValue] != nil { + + // Column? + if let column = try? decodeColumn(forKey: key), + let index = row.index(forColumn: column) + { + return row.hasNull(atIndex: index) + } + + // Scope? + if let scopedRow = row.scopesTree[key.stringValue] { + return scopedRow.containsNonNullValue == false + } + + // Prefetched Rows? + if let prefetchedRows = row.prefetchedRows[key.stringValue] { return false } + + // Unknown key return true }