Fix: NULL column incorrectly reported as ColumnNotFound instead of UnexpectedNullableFound#665
Fix: NULL column incorrectly reported as ColumnNotFound instead of UnexpectedNullableFound#665
Conversation
…d in parseColumn Co-authored-by: gaeljw <18280708+gaeljw@users.noreply.github.com>
|
@copilot what are the impacts of such a change? How will callers handle the new error instead of ColumnNotFound? |
…l column with ? operator Co-authored-by: gaeljw <18280708+gaeljw@users.noreply.github.com>
Good catch — the original fix was incomplete. The key impact was on The fix in commit
|
When parsing a non-nullable scalar from a column containing SQL NULL, Anorm threw a misleading
ColumnNotFounderror listing the column as both not-found and available — hiding the real cause.Root cause
SqlParser.parseColumnwas remappingUnexpectedNullableFound→ColumnNotFound:Changes
SqlParser.scala: Remove the erroneousUnexpectedNullableFound→ColumnNotFoundmapping inparseColumn. The method now returnsc.tupled(input)directly, propagating the original error.RowParser.scala: Update the?operator to also catchUnexpectedNullableFound→None, preserving its documented behaviour of turning a missing or null column intoNone. Previously this worked accidentally via the wrongColumnNotFoundmapping.AnormSpec.scala: Add regression test asserting thatscalar[Int].singleon a NULL integer column throwsAnormExceptionwith anUnexpectedNullableFound(...)message.SqlResultSpec.scala: Add test asserting thatSqlParser.int("n").?on a NULL integer column returnsNone.The net observable behaviour for callers:
get[Int]("col").singleon NULLColumnNotFound(misleading)UnexpectedNullableFound(correct)get[Int]("col").?on NULLNoneNone(unchanged)get[Int]("col").singleon missing columnColumnNotFoundColumnNotFound(unchanged)🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.