Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Conversation

kfujita-cohere
Copy link
Contributor

Overview

Our team has noticed that null values do not persist when unsetting nested embedded fields, unless the field is an EmbeddedCollection. After debugging the code, we noticed that the pathways for Embedded and EmbeddedCollection were slightly different:

EmbeddedCollection Pathway

def embeddedUpdate = encodeUpdate(o, createEntityAccess(o), EncoderContext.builder().build(), true)
This call to encodeUpdate passes through embedded = true.

Embedded Pathway

def embeddedUpdate = encodeUpdate(v)
This call to encodeUpdate defaults to embedded = false.

Root cause of failure to unset null fields on updates

The unsets array never receives the prop.name key of the embedded fields going through the Embedded pathway, because of the following code:

else if(embedded || !isNew) {
        unsets[prop.name] = BLANK_STRING
}

Solution

This PR passes through embedded = true in both the Embedded and EmbeddedCollection pathways.

@CLAassistant
Copy link

CLAassistant commented Nov 29, 2023

CLA assistant check
All committers have signed the CLA.

@kfujita-cohere
Copy link
Contributor Author

kfujita-cohere commented Nov 29, 2023

Validation steps

  • Build the local jar file for grails-datastore-gorm-mongodb on branch 7.0.x (version we are currently using)
  • Build the local jar file for grails-datastore-gorm-bson on branch 7.0.x (version we are currently using). This is needed because the next step removed it from our libraries somehow.
  • exclude group: 'org.grails', module: 'grails-datastore-gorm-mongodb' from the compile of org.grails.plugins:mongodb
  • Add implementation(files({absolute path to mongodb jar}))
  • Add implementation(files({absolute path to bson jar}))
  • Run through the same test case where the embedded null object was not persisting as null in the database, ensuring that it is now nullified

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants