Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added datastore property to registeredDryModels #467

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added datastore property to registeredDryModels #467

wants to merge 2 commits into from

Conversation

sveingunnarlarsen
Copy link

Added datastore to registeredDryModels as teardown uses this property to remove models from the adapter, i.e.

    try {
      delete registeredDsEntries[datastoreName];

      _.each(_.keys(registeredDryModels), function(modelIdentity) {
        if (registeredDryModels[modelIdentity].datastore === datastoreName) {
          delete registeredDryModels[modelIdentity];
        }
      });

    } catch (e) { return done(e); }

In registerDatastore the property datastore is not added to registeredDryModels, i.e.

        if (registeredDryModels[phModelInfo.identity]) {
          throw new Error('Consistency violation: Cannot register model: `' + phModelInfo.identity + '`, because it is already registered with this adapter!  This could be due to an unexpected race condition in userland code (e.g. attempting to initialize multiple ORM instances at the same time), or it could be due to a bug in this adapter.  (If you get stumped, reach out at http://sailsjs.com/support.)');
        }

        registeredDryModels[phModelInfo.identity] = {
          primaryKey: phModelInfo.primaryKey,
          attributes: phModelInfo.definition,
          tableName: phModelInfo.tableName,
          identity: phModelInfo.identity,
        };

Which means that registeredDryModels[modelIdentity].datastore will always be undefined and not remove the model from registeredDryModels causing registerDatastore to throw "Consitency violation" error if you need to reinitialize waterline.

@tugorez
Copy link

tugorez commented Jun 20, 2018

I can confirm there is a problem if you, like me, are trying to use a test watcher and need to reinitialize waterline. Is there any problem with this PR ? @particlebanana @mikermcneil

tugorez added a commit to spaceship-labs/sails-mongo that referenced this pull request Jun 20, 2018
be able to remove the model from registeredDryModels
so we can avoid registerDatastore to throw "Consitency violation" error
if you need to reinitialize waterline.
please see balderdashy#467 for more
information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants