Skip to content

automatic dirty checking not working on array type #106

Description

@nicsl0s

In a grails app I have a domain class like this:

class User {
         String[] privileges = ['JUNIOR_BIZDEV','TECHNICAL_ADMIN']
 
         Set<String> getPrivilegesSet() {
                return privileges.collect {it } as Set<String>
         }

        // convenience method to modify the user privileges
        void addToPrivilegesSet(String privilege) {
               def tmp = privilegesSet
               tmp.add(privilege)
               privileges = tmp.collect { it } as String[]
        }
}

// calling user somewhere
def user = User.get(SOME_ID)
user.addToRoleSet('JUNIOR_SOMETHING_ADMIN') // this causes the privileges to be dirty and the user got saved with a further role
user.save()

This used to work when using:
org.grails.plugins:postgresql-extensions:4.6.2
grails version 3.2.8
gorm version 6.0.9.RELEASE

This stopped working when using:
grails version 3.2.9
gorm version 6.1.4.RELEASE

I think the reason is some change in the new gorm version. It stops working since version gorm 6.1.0
Also using the org.grails.plugins:postgresql-extensions:5.1.0 did not change it.
The workaround was to add a markDirty() in the convenience method:

  void addToPrivilegesSet(String privilege) {
               def tmp = privilegesSet
               tmp.add(privilege)
               privileges = tmp.collect { it } as String[]
               markDirty('privileges')
        }

Any Hints?
Thx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions