apache / apache/grails-core

Async Gorm - onComplete doesn't render JSON in a controller of the owner side

Open
#9,941 7 comments 0 reactions 0 assignees View on GitHub
info: workaround available
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Using Grails 3.1.6, the owner side of an association (one-to-many, many-to-many.....) doesn't get JSON rendering when used in a method with Async Gorm in a Controller.

E.g.: Campus has many courses and a Course belongs to a Campus (bidirectional one-to-many relationship).
### Task List
- [X] Steps to reproduce provided
- [ ] Stacktrace (if present) provided
- [ ] Example that reproduces the problem uploaded to Github
- [X] Full description of the issue provided (see below)
### Steps to Reproduce
1. Create a bidirectional one-to-many relationship (E.g.: Campus has many Courses and Course belongs to Campus)
2. In Bootstrap and Controllers:

```
Campus.async.findAllByNomeIlike("%man%").onComplete{ results ->
println results.value //Bootstrap
render results.value //Controller
}

Course.async.findAllByNomeIlike("%tec%").onComplete{ results ->
println results.value //Bootstrap
render results.value //Controller
}
```
1. In Bootstrap and Controllers, this works:

```
Campus.async.findAllByNomeIlike("%$params.q%").onComplete{ results ->
render results.value as JSON //doesn't work
}

Course.async.findAllByNomeIlike("%$params.q%").onComplete{ results ->
render results.value as JSON //this works
}
```
### Expected Behaviour

Async JSON should be rendered at both sides. In CampusController, this shoukd work:

```
def getCampus() {
Campus.async.findAllByNomeIlike("%$params.q%").onComplete{ results ->
render results.value as JSON
}
}
```

But it doesn't.

In CourseController, this works:

```
def getCourses() {
Course.async.findAllByNomeIlike("%$params.q%").onComplete{ results ->
render results.value as JSON
}
}
```
### Actual Behaviour

The following happens after an unsuccessful "render results.value as JSON" on the owner side:

```


  • An error has occurred

  • Exception:

  • Message:

  • Path:


```
### Environment Information
- **Operating System**: Windows 7 (64-bit)
- **Grails Version:** 3.1.6
- **JDK Version:** Oracle 1.8.0.77
- **Container Version (If Applicable):** not applicable

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue in the Grails 3.1.6 setup described, using the bidirectional Campus/Course association and the two controller methods shown. Compare JSON rendering for the owner and inverse sides; done means both async controller queries render their association results as JSON without the reported error page.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.