Keystone-classic: require: true in save method isn't work

Created on 31 May 2018  路  5Comments  路  Source: keystonejs/keystone-classic

Expected behavior



SOME ERROR link image not found, or link not found

Actual/Current behavior



(err = null) and model save correctly

Steps to reproduce the actual/current behavior


  1. change some model
Banner.add({
    name: {
        type: Types.Text,
        initial: true,
    },
    image: {
        type: Types.Url,
        require: true,
        initial: true,
    },
    link: {
        type: Types.Url,
        require: true,
        initial: true,
    },
    order: {
        type: Types.Select,
        default: 0,
        initial: true,
        numeric: true,
        options: [{
            value: 1,
            label: 'First',
        }, {
            value: 2,
            label: 'Second',
        }, {
            value: 3,
            label: 'Third',
        }, {
            value: 4,
            label: 'Fourth',
        }, {
            value: 5,
            label: 'Fifth',
        }, {
            value: 0,
            label: 'None',
        }],
        emptyOption: false,
    },
});
  1. create new model
const model = new Banner.model({});
  1. save model
model.save(err => {
    if (err) console.error(err);
    else console.log(model);
});

4.1 EXPECTED: SOME ERROR image not found, link not found
4.2 ACTUAL: (err = null) and model save correctly

Environment

| Software | Version
| ---------------- | -------
| Keystone | 4.0.0-beta.5
| Node | v9.11.1

question

Most helpful comment

you mean required?

All 5 comments

@kamontat Keystone 4.0.0-beta.5 was released in Jan 2017. Can you please retest with 4.0.0-beta.8 and confirm if the issue is still reproducible?

Thanks,
Stennie

I already update the newest version, and the bug is still exist.

With some condition

  1. When create models using new Model.model(), you need to pass autokey path (e.g. id) into it. otherwise it will return error
MongoError: E11000 duplicate key error collection: base-website.banners index: id_1 dup key: { : null }
  1. My models setting
var Banner = new keystone.List('Banner', {
    autokey: {
        from: 'name image',
        path: 'id',
        unique: true,
    },
    track: true,
});

@kamontat Great, thanks for confirming and including details to reproduce.

Regards,
Stennie

you mean required?

@laurenskling Good catch! We're trying to clean up the backlog of Keystone issues to get 4.0 out, so any help greatly appreciated :).

@kamontat, your original model has require:true instead of required:true which is allowing you to save with those fields missing.

If you are using name image as the autokey and both values are null, the unique indexed value will also be null and result in the duplicate key error you've encountered.

If you use the expected required attribute this should not be an issue. You'll also need to edit or remove any documents which have the expected fields missing.

Regards,
Stennie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhdan88vadim picture zhdan88vadim  路  5Comments

sorryididntmeantto picture sorryididntmeantto  路  3Comments

stennie picture stennie  路  5Comments

calebmcelroy picture calebmcelroy  路  3Comments

webteckie picture webteckie  路  5Comments