question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v0.9.8 - 'Unlink' never removes previous link relation changes.

See original GitHub issue

Love the package! It’s been very helpful of late, but I’ve noticed an issue 😃

I noticed that if you persist a parent model in memory, the relationChanges array just continues to grow as you link and unlink objects to the parent object.

It looks like there is a check failing in the unlink function for a couple of reasons.

In source, the function looks like this:

exports.unlink = function unlink(obj, options, callback) {

  if (typeof(options) === 'string') {
    options = {name: options};
  }
  var opts = h.$extend({
    name: 'default'
  }, options);

  callback = h.getCallback(arguments);
  
  var changes = this.relationChanges;
  for (var i in changes) {
    if (changes.hasOwnProperty(i) &&
        changes[i].name === opts.name &&
        h.checkEqual(changes[i].object, obj)) {
      delete this.relationChanges[i];
    }
  }
  
  this.relationChanges.push({
    action: 'unlink',
    options: opts,
    callback: callback,
    object: obj
  });
};

First, changes[i].name === opts.name will always evaluate false, as the relation name is actually at changes[i].options.name.

Second, delete this.relationchanges will leave an ‘undefined’ object in the array at the index, causing issues further downstream. You’re better off using this.relationChanges.splice(i, 1);

Third, in the h.checkEqual() function, there is a conditional as below:

else if (obj1.hasOwnProperty('modelName') && obj2.hasOwnProperty('modelName') &&
           obj1.modelName === obj2.modelName) {

This will exclude the entire second half of the function, as the modelName attribute is located at obj1.__proto__.modelName

I’ll prepare a PR with the appropriate changes to fix the issue. I’m not fussed if you would rather approach the issue in a different manner, but we’re keen to get this merged to avoid issues with patching at build.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lp-belliotcommented, Apr 4, 2018

I’ve put the changes here:

https://github.com/lp-belliot/nohm/tree/feature/fix_bug_in_unlink_function

Not sure what to do given master is well past the v0.9.8 commit.

1reaction
maritzcommented, Apr 4, 2018

Sure, I just won’t spend much time on it in v1. 😉
But I can certainly read, accept/decline PRs and publish new versions.

The checkEqual is still the same in v2, the other 2 problems are already fixed in v2.

@lp-belliot thanks for the report & PR! Can you add some unit tests that fail without your changes? If possible one for each of the 3 problems you found.

Read more comments on GitHub >

github_iconTop Results From Across the Web

backstage/CHANGELOG.md at master - GitHub
Modules that build on top of the catalog backend plugin should switch all of their imports to the @backstage/plugin-catalog-node package and remove the ......
Read more >
XBLUE X50 Downloads
Sometimes the software of the XBLUE server changes and requires that the software of the XBLUE IP telephone also be changed. Please take...
Read more >
Age of Modding v0.9.8.0 Released! A revolutional PC ...
After months of silence, finally I'm coming back with the brand-new Age of Modding v0.9.8.0 UPDATE! - You are a new modder, you...
Read more >
ELSA-2022-9117 - Unbreakable Linux Network - Oracle
Remove bogus file from /usr/share/doc, introduced by fix for bug #1092035 ... reverted previous change, koji doesn't like it
Read more >
Decentralized Identifiers (DIDs) v1.0 - W3C
Abstract. Decentralized identifiers (DIDs) are a new type of identifier that enables verifiable, decentralized digital identity. A DID refers to any subject ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found