Grails
  1. Grails
  2. GRAILS-8436

Grails datastore Custom types are failing to check isDirty()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-RC3
    • Fix Version/s: 2.0.1
    • Component/s: Persistence, Testing
    • Labels:
    • Environment:
      Kubuntu linux, Intellij IDEA 10.5

      Description

      I use Joda Time plugin and it provides dateCreated and lastUpdated fields. In unit tests all instances that are saved for the second time in a test fail to pass NativeEntryEntityPersister#isDirty method. This is because they are instances of class org.grails.datastore.mapping.model.types.Custom and it's not included in this method. There is a simple fix, change this line:

                  if (prop instanceof Simple || prop instanceof Basic || prop instanceof ToOne ) {
                      if (!areEqual(oldValue, currentValue, key)) {
                          return true;
                      }
                  }
      

      into:

                  if (prop instanceof Simple || prop instanceof Basic || prop instanceof ToOne || prop instanceof Custom ) {
                      if (!areEqual(oldValue, currentValue, key)) {
                          return true;
                      }
                  }
      

        Activity

        Hide
        Robert Fletcher added a comment -

        That fix will work for Joda-Time as it does not perform any type conversion when writing values to the simple datastore. However for some custom types the value of currentValue will actually be the stored serializable value whilst oldValue is the correct custom type & they will not be directly comparable.

        I'm working on a patch right now.

        Show
        Robert Fletcher added a comment - That fix will work for Joda-Time as it does not perform any type conversion when writing values to the simple datastore. However for some custom types the value of currentValue will actually be the stored serializable value whilst oldValue is the correct custom type & they will not be directly comparable. I'm working on a patch right now.
        Hide
        Robert Fletcher added a comment -

        I think what I need to do is figure out how I can get hold of the CustomTypeMarshaller for the type in question and either read the native version of the currentValue variable or convert the oldValue variable to the target property type so that the comparison can be done.

        I'm not sure if there's somewhere I can look up the marshaller, though.

        Show
        Robert Fletcher added a comment - I think what I need to do is figure out how I can get hold of the CustomTypeMarshaller for the type in question and either read the native version of the currentValue variable or convert the oldValue variable to the target property type so that the comparison can be done. I'm not sure if there's somewhere I can look up the marshaller, though.
        Hide
        Robert Fletcher added a comment -

        There's a pull request here with a fix: https://github.com/SpringSource/grails-data-mapping/pull/24

        Show
        Robert Fletcher added a comment - There's a pull request here with a fix: https://github.com/SpringSource/grails-data-mapping/pull/24
        Hide
        Graeme Rocher added a comment -

        Thanks

        Show
        Graeme Rocher added a comment - Thanks

          People

          • Assignee:
            Unassigned
            Reporter:
            Tomasz Kalkosinski
          • Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development