Setting embedded Shape object to null doesn't work in 7.0.7
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
My domain classes are like:
```
@Entity
class Arbitrary {
String id
Map data
Geometry geometry
static embedded = [ 'data', 'geometry' ]
}
```
and
```
import grails.mongodb.geo.MultiPoint
@Entity
class Geometry {
MultiPoint points
}
```
Setting the `arbitrary.data = null` in controller works just fine, but `arbitrary.geometry = null` is ignored.
In order to dance the problem around, I defined a fake constant and the checker method in Geometry class, like so:
```
class Geometry {
...
static final KINDA_NULL = new Geometry( points:MultiPoint.valueOf( [ [ 0, 0 ] ] ) )
boolean kindaNull() {
points == KINDA_NULL.points
}
}
```
and added the interceptor into Arbitrary class like so:
```
class Arbitrary {
...
def afterUpdate() {
if( geometry.kindaNull() )
Arbitrary.collection.update( [ _id:getId() ], [ $unset:[ geometry:1 ] ] )
}
}
```
Then it works kinda as expected.
Contributor guide
Research direction
Start by reproducing the issue with the Arbitrary and Geometry domain classes shown in the report, focusing on how the embedded geometry is persisted when set to null. Compare that behavior with setting data to null and inspect the embedded-object update path. Done means assigning geometry = null removes the embedded geometry without a workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, mongodb
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100