Skip to content

[Akka Streams] Errors in query do not make the materialized value fail #457

@gaeljw

Description

@gaeljw

Anorm Version (2.5.x / etc)

anorm + anorm-akka 2.6.10

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

Linux 5.17.4-200.fc35.x86_64 #1 SMP PREEMPT Wed Apr 20 15:37:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

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

openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment 18.9 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.14.1+1, mixed mode, sharing)

Library Dependencies

akka-stream 2.6.19

Expected Behavior

Considering the following code:

implicit val connection = ???

AkkaStream
  .source(SQL("SELECT non_existing FROM table"), rowParser)
  .mapMaterializedValue(_.onComplete(_ => connection.close()))

Connection is automatically closed in case of success or errors within the row parser thanks to the materialized value handling.

I would expect the materialized value to be a Future.failed in case the SQL query is invalid (like selecting an wrong field).

Actual Behavior

Actual behavior is that there's no materialized value, it fails in preStart of the stream and connection is not closed:

[error] a.a.RepointableActorRef - Error during preStart in [anorm.AkkaStream$ResultSource$$anon$1]: Query failed (#20220511_130845_00043_erkzk): line 1:8: Column 'non_existing' cannot be resolved
java.sql.SQLException: Query failed (#20220511_130845_00043_erkzk): line 1:8: Column 'non_existing' cannot be resolved
        at io.trino.jdbc.AbstractTrinoResultSet.resultsException(AbstractTrinoResultSet.java:1937)
	at io.trino.jdbc.TrinoResultSet.getColumns(TrinoResultSet.java:285)
	at io.trino.jdbc.TrinoResultSet.create(TrinoResultSet.java:61)
	at io.trino.jdbc.TrinoStatement.internalExecute(TrinoStatement.java:262)
	at io.trino.jdbc.TrinoStatement.execute(TrinoStatement.java:240)
	at io.trino.jdbc.TrinoPreparedStatement.executeQuery(TrinoPreparedStatement.java:135)
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
	at anorm.Sql.unsafeResultSet(Anorm.scala:82)
	at anorm.Sql.unsafeResultSet$(Anorm.scala:81)

Thanks for any comments on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions