Fix: NULL column incorrectly reported as ColumnNotFound instead of UnexpectedNullableFound#665
Fix: NULL column incorrectly reported as ColumnNotFound instead of UnexpectedNullableFound#665Copilot wants to merge 3 commits into
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
|
…nNotFound
Previously, NULL columns triggered an `UnexpectedNullableFound` error
from `Column[T]`, but `SqlParser`'s internal `parseColumn` helper
remapped it to `ColumnNotFound`, producing misleading "column not found"
errors like "'X' not found, available columns: X, X" where the column
was actually present and merely contained NULL.
The fix drops the remap, and the now-trivial `parseColumn` helper is
inlined at its three call sites. The `.?` combinator on `RowParser`
previously depended on the remap to convert NULL to `None`; it now
recovers from `UnexpectedNullableFound` directly, honouring its
documented "missing or null column as None" contract.
Tests:
- AnormSpec: scalar[String].single on NULL must surface
UnexpectedNullableFound, not "not found, available columns".
- SqlResultSpec: int("n").? on NULL returns None (parity with the
existing str("foo").? coverage, on the Column[Int] codepath; mirrors
the coverage added in playframework#665).
Closes playframework#560.
Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
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.