playframework / anorm

The Anorm database library
https://playframework.github.io/anorm/
Apache License 2.0
240 stars 75 forks source link

Incorrect error message when column is unexpectedly NULL #560

Open simondean opened 1 year ago

simondean commented 1 year ago

Are you looking for help?

No

Anorm Version (2.5.x / etc)

2.7.0 (latest version)

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

Use uname -a if on Linux.

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

Adopt JDK 11

Library Dependencies

N/A

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. Use the scalar[Int].single on a column that unexpectedly contains a NULL
  2. An error is thrown that says the column unexpectedly contains a null

Actual Behavior

  1. Use the scalar[Int].single on a column that unexpectedly contains a NULL
  2. This error is thrown: anorm.AnormException: '.completed_average' not found, available columns: completed_average, completed_average
  3. The error makes it look like there was an issue with column name or column alias etc. The actual issue was that the column unexpectedly contains a NULL and the scalar[Option[Int]].single needs to be used instead

The issue seems to be with this code in Anorm:

  @inline private def parseColumn[T](
      row: Row,
      name: String,
      c: Column[T],
      input: (Any, MetaDataItem)
  ): Either[SqlRequestError, T] = c.tupled(input).left.map {
    case UnexpectedNullableFound(_) =>
      ColumnNotFound(name, row)

    case cause => cause
  }

The UnexpectedNullableFound error is incorrectly mapped to the ColumnNotFound error

Reproducible Test Case

Please provide a PR with a failing test.

If the issue is more complex or requires configuration, please provide a link to a project on Github that reproduces the issue.

gaeljw commented 9 months ago

I've been facing this a few times as well. I'm used to it now but would be better if fixed indeed :)