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

Validator called more than once (5.6.9), called never (5.6.11) #8117

Closed
qqilihq opened this issue Aug 31, 2019 · 1 comment
Closed

Validator called more than once (5.6.9), called never (5.6.11) #8117

qqilihq opened this issue Aug 31, 2019 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@qqilihq
Copy link

qqilihq commented Aug 31, 2019

Do you want to request a feature or report a bug?
Bug.

What is the current behavior?
This is a follow-up for #8067

Scenario: Validator is used on an object property. With 5.6.9 the validator gets called several times, with 5.6.11 it gets not called at all.

If the current behavior is a bug, please provide the steps to reproduce.

const mongoose = require('mongoose'); // no mongoose.version when using import?!

(async () => {
  const Model = mongoose.model('model', new mongoose.Schema({
    name: { type: String },
    level1: {
      level2: {
        type: Object,
        validate: {
          validator: (v: any) => {
            console.log('called validator with', v);
            return true;
          }
        }
      }
    }
  }));

  const doc = new Model({ name: 'bob' });
  console.log(mongoose.version);
  doc.level1 = { level2: { a: 'one', b: 'two', c: 'three' } };
  await doc.validate();
  console.log('done');
})().catch(err => console.error(err));

Running with Mongoose 5.6.9 I see:

$ ./node_modules/.bin/ts-node ./src/mongoose-8067.ts 
5.6.9
called validator with { a: 'one', b: 'two', c: 'three' }
called validator with one
called validator with two
called validator with three
done

Running with Mongoose 5.6.11 I see:

$ ./node_modules/.bin/ts-node ./src/mongoose-8067.ts 
5.6.11
done

I admittedly didn't try the version in between :-P

What is the expected behavior?
The validator should execute once with { a: 'one', b: 'two', c: 'three' }

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

@tho-masn
Copy link

tho-masn commented Sep 2, 2019

I observed the same behaviour (see also here: #8113)
Looks like this misbehaviour got introduced in 5.6.10

@vkarpov15 vkarpov15 added this to the 5.6.13 milestone Sep 4, 2019
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Sep 4, 2019
vkarpov15 added a commit that referenced this issue Sep 4, 2019
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Sep 4, 2019
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

3 participants