foundryvtt
foundryvtt copied to clipboard
Update validation allows creating invalid items.
What happened?
When using required fields in arrays, FoundryVTT accepts updates that do not contain the field for every entry, thereby creating items that are invalid (see log below, which is a correct validation failure).
It is my expectation that the update validation rejects updates that would create an invalid item.
What ways of accessing Foundry can you encounter this issue in?
- [X] Native App (Electron)
- [ ] Chrome
- [X] Firefox
- [ ] Safari
- [ ] Other
Reproduction Steps
- Define a
DataModelwith an embedded model array containing a required field, e.g.:
class TestModel extends foundry.abstract.DataModel {
static defineSchema() {
return {
path: new foundry.data.StringField({ required: true, blank: false, readonly: true }),
value: new foundry.data.NumberField({ integer: true }),
};
}
}
export default class MyItemData extends foundry.abstract.DataModel {
static defineSchema() {
return {
validationTest: new foundry.data.ArrayField(new fields.EmbeddedDataField(TestModel)),
};
}
}
- Register the data model for any item type and create a valid item of that type.
- Update the item with invalid data:
item.update({ "system.validationTest": [{ value: 0 }] }) - Observe how the update is accepted, but the item disappears because it is now invalid (see error below).
What core version are you reporting this for?
11.315
Relevant log output
Error: Failed to initialize Item [t5l9qimzydodvfvp] in Actor [MGLszUc5xrMRyesa]: TestModel validation errors:
path: may not be undefined
at DataModelValidationFailure.asError (C:\Program Files\Foundry Virtual Tabletop\resources\app\public\scripts\commons.js:3894:14)
at TestModel.validate (C:\Program Files\Foundry Virtual Tabletop\resources\app\public\scripts\commons.js:7164:61)
at new DataModel (C:\Program Files\Foundry Virtual Tabletop\resources\app\public\scripts\commons.js:6918:12)
at new TestModel (F:\Archive\Code\Repositories\Git\FVTT TDE5\dist\module\items\model\combatTechniqueData.js:4:1)
at EmbeddedDataField.initialize (C:\Program Files\Foundry Virtual Tabletop\resources\app\public\scripts\commons.js:6023:14)
at C:\Program Files\Foundry Virtual Tabletop\resources\app\public\scripts\commons.js:5903:42
at Array.map (<anonymous>)
at ArrayField.initialize (C:\Program Files\Foundry Virtual Tabletop\resources\app\public\scripts\commons.js:5903:20)
Bug Checklist
- [X] The issue occurs while all Modules are disabled
Thanks for the report.