This repository was archived by the owner on Aug 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -147,3 +147,34 @@ Note that data validation is not applied when instantiating a schema instance
147147directly from an instance or dictionary. This should be used when creating
148148instances against a data source that is already known to be validated, such as
149149when loading existing instances from a database.
150+
151+ ## Using strict validation
152+
153+ By default, additional properties in the incoming user data is ignored.
154+
155+ ``` python
156+ data = {
157+ ' title' : ' Double Negative' ,
158+ ' release_date' : ' 2018-09-14' ,
159+ ' artist' : {' name' : ' Low' },
160+ ' num_tracks' : 11
161+ }
162+ ```
163+
164+ After validating against the schema, the ` num_tracks ` property is not present
165+ on the ` album ` instance.
166+
167+ ``` python
168+ album = Album.validate(data)
169+ album.num_tracks
170+ # AttributeError: 'Album' object has no attribute 'num_tracks'
171+ ```
172+
173+ If you use strict validation, additional properties becomes an error instead.
174+
175+ ``` python
176+ album, error = Album.validate_or_error(data, strict = True )
177+
178+ print (dict (error))
179+ # {'num_tracks': 'Invalid property name.'}
180+ ```
You can’t perform that action at this time.
0 commit comments