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

Overloaded schema fails to trigger due to kareem update to 2.0.5 #6250

Closed
gforge opened this issue Mar 16, 2018 · 1 comment
Closed

Overloaded schema fails to trigger due to kareem update to 2.0.5 #6250

gforge opened this issue Mar 16, 2018 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@gforge
Copy link

gforge commented Mar 16, 2018

In the mongoose-delete plugin (dsanel/mongoose-delete#36) the tests started failing when kareem package was updated to version 2.0.5. After some debugging it turns out that this only occurs when passing a callback function to the the overloaded function. I've created a test case that fails on the last assertion:

it('statics', async (done) => {
  var called = false;
  var filter_plugin = function(schema) {
    schema.add({ filter: Boolean })
    schema.statics.count = function() {
      called = true;
      return mongoose.Model['count'].apply(this, arguments).where('filter').eq(true);
    }
  }

  var TestSchema = new Schema({ name: String });
  TestSchema.plugin(filter_plugin);
  var TestModel = db.model('PluginTests', TestSchema);

  await TestModel.create(
      [
          { name: 'Obi-Wan Kenobi', filter: true},
          { name: 'Darth Vader'},
          { name: 'Luke Skywalker', filter: true}
      ]);

  assert.equal(called, false);
  var count = await TestModel.count();
  assert.equal(called, true);
  assert.equal(count, 2);

  return TestModel.count(function (err, count) {
    assert.equal(called, true);
    assert.equal(count, 2);
    done();
  })
});

The error is due to this commit: mongoosejs/kareem@5afc5b9 I'm not sure though if where this bug belongs. Since the failure above doesn't use hooks, I've decided to first post the issue here.

A full standalone test-file is available in my fork: https://github.com/gforge/mongoose/blob/master/test/schema.plugins.test.js

@vkarpov15
Copy link
Collaborator

Thanks for reporting, will fix ASAP 👍

@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Mar 21, 2018
@vkarpov15 vkarpov15 added this to the 5.0.12 milestone Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants