Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    [BUG] function isc.DataSource._applySparseAndNoNullUpdates() removes "logicalTime" property from Date objects.

    Hi Isomorphic,

    I've debugged some strange issues with DynamicForm "time" fields and discovered that code in isc.DataSource._applySparseAndNoNullUpdates on Date object if they not match it falls thru and thinks that it's just some Object and recursively checks their internal attributes.
    By doing that _applySparseAndNoNullUpdates compares internal Date attributes as "logicalDate" "logicalTime" and it sees that they haven't changes and removes attributes from the object. This will instantly make Date objects which has been marked as logical to be not logical and this causes troubles ahead - e.g. serialisation now serialise these in full datetime format during request submission.

    Tested on 13.0d, but I feel that this issue is in all versions of the SmartClient.

    DataSource._applySparseAndNoNullUpdate:

    Code:
                    if (isc.isA.Date(value) && isc.DateUtil.compareDates(value, oldValue) == 0) {  // <- IF THEY MATCH THEN, NO CHANGES, REMOVE FROM LIST, BUT IF NOT MATCH...
                        delete values[key];
                    } else if (isc.isAn.Array(value)) { // NOT AN ARRAY, ALL OK.
                        for (var i = 0; i < value.length; i++) {
                            this._applySparseAndNoNullUpdates(value[i], oldValue[i], operationType,
                                            field == null ? null : isc.DataSource.get(field.type));
                            var keyCount = 0;
                            for (var k2 in value[i]) keyCount++;
                            if (keyCount == 0) delete value[i];
                        }
                        // If this process leaves an array full of nulls, don't bother serializing it
                        var goodEntry = false;
                        for (var i = 0; i < value.length; i++) {
                            if (value[i] != null) {
                                goodEntry = true;
                                break;
                            }
                        }
                        if (!goodEntry) delete values[key];
                    } else if (isc.isAn.Object(value)) {                                              //  >>-- FAIL HERE <<- the Date is also an Object, so it starts recursive checking of internal Date properties ?? 
                        this._applySparseAndNoNullUpdates(value, oldValue, operationType,
                                            field == null ? null : isc.DataSource.get(field.type));
                        // If this process leaves an object with no properties, get rid of it
                        var keyCount = 0;
                        for (var k2 in value) keyCount++;
                        if (keyCount == 0) delete values[key];
                    } else if (value == oldValue) {
                        delete values[key];
                    }
    Suggested solution: (just check if its Date and if it is do second check if values matches).

    Code:
         if (isc.isA.Date(value)) {
              if (isc.DateUtil.compareDates(value, oldValue) == 0) {
                    delete values[key];
              }
         } else if .....

    Sadly I cannot see any workarounds for this issue... only by replacing entire function body with a patched version :)

    Please, apply this fix into further versions.


    #2
    Some workaround for debug version:
    Code:
     (function() { const parent = {     _applySparseAndNoNullUpdates: isc.DataSource.getPrototype()["_applySparseAndNoNullUpdates"] }  isc.DataSource.addMethods({     _applySparseAndNoNullUpdates: function (values: any) {         if (isc.isA.Date(values)) return;         return parent._applySparseAndNoNullUpdates.apply(this, arguments);     } }) })();

    Comment


      #3
      Thanks for letting us know about the problem and for pinpointing the faulty logic.
      We've made a change to address this in 12.1 13.1. It will be present in nightly builds going forward (dated Nov 6 and above)

      Regards
      Isomorphic Software

      Comment


        #4
        Great! Thank you!

        Comment

        Working...
        X