stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.72k stars 1.57k forks source link

bug in optional support for decoding #1247

Closed Chris-Stockbridge closed 7 months ago

Chris-Stockbridge commented 8 months ago

If a table includes an optional custom struct, the decode method throws an error when the optional value is nil

I created a unit test demonstrating this here: https://github.com/stephencelis/SQLite.swift/compare/master...Chris-Stockbridge:SQLite.swift:master d5b2adc48a2a458b6e366d39a1ffa060381c3912

This unit test passes with the previous release, but breaks starting with 0.15.0

Chris-Stockbridge commented 8 months ago

I think the issue comes from https://github.com/stephencelis/SQLite.swift/blob/e78ae0220e17525a15ac68c697a155eb7a672a8e/Sources/SQLite/Typed/Coding.swift#L507 nil is a valid return value here. If row.get() throws, then this method should fail, but if the return value is nil then decodeIfPresent() should return nil.