spring-projects / spring-projects/spring-data-mongodb

Reactive Mongo with Kotlin suspend functions

Open
#3,886 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

When writing ReactiveMongoRepository/ReactiveCrudRepository with spring-boot-starter-data-mongodb-reactive and declaring suspend find function with non-nullable kotlin return types, the repository returns null when it can't find an entity instead of EmptyResultDataAccessException.

Here is the fun declaration:
suspend fun findSomeEntitiesById(id: Long): SomeEntity

And this test prints null when called with id that does not exists:

@Test internal fun returnsNllReference() { runBlocking { println(repositoryMy.findSomeEntitiesById(123)) } }

If I replace spring-boot-starter-data-mongodb-reactive with spring-boot-starter-data-r2dbc, it throws

org.springframework.dao.EmptyResultDataAccessException: Result must not be null!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ReactiveMongoRepository/ReactiveCrudRepository suspend function entry point and compare its missing-entity behavior with the spring-boot-starter-data-r2dbc example. Reproduce the non-nullable Kotlin query using id 123; done means a missing entity raises EmptyResultDataAccessException instead of returning null, with a regression test covering that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, mongodb, spring
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.