Skip to content

Commit da588e5

Browse files
committed
Document marshmallow library as an option
Signed-off-by: Martin Vrachev <[email protected]>
1 parent d328626 commit da588e5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

docs/adr/0007-validation-guideliness.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ attributes in the middle of function execution.
3131
## Considered Options
3232
1. Usage of a `ValidationMixin`.
3333
2. Usage of a third-party library called `pydantic`.
34+
3. Usage of a third-part library called `marshmallow`.
3435

3536
## Pros, Cons, and Considerations of the Options
3637

@@ -173,10 +174,55 @@ This was concluded by performing the following steps:
173174
functions with a name begging with `_validate`, the same way it's done in the
174175
`ValidationMixin` implementation in `in-toto`.
175176

177+
### Option 3: Usage of a third-part library called "marshmallow"
178+
179+
Here is how this option compares against our
180+
(requirements)[#decision-drivers-and-requirements]:
181+
182+
| Number | Stance |
183+
| ----------- | ----------- |
184+
| 1 | It can validate only class attributes. |
185+
| 2 | Yes, it allows that. |
186+
| 3 | Likely slower than pydanitc (according to [pydantic](https://pydantic-docs.helpmanual.io/benchmarks/)). |
187+
| 4 | It adds 1 additional dependency. |
188+
| 5 | Yes, it does support all of our python versions. |
189+
| 6 | Yes, it does allow that. |
190+
| 7 | Yes, it allows that through `validate()` function. |
191+
192+
Additional thoughts:
193+
194+
* Good, because it allows for strict type checks by marking the class attributes
195+
(or Fields as they call them) as `strict`.
196+
197+
* Good, because it provides additional custom types (with their own built-in
198+
validation) like `URL`, `IPv4`, `IPv6`, etc.
199+
200+
* Bad, because it's created with schemas in mind and a heavy focus on
201+
serialization and deserialization. Most of the features are not related
202+
to validation.
203+
204+
* Bad, because it adds one additional dependency - itself.
205+
This was concluded by performing the following steps:
206+
1. Creating a fresh virtual environment with python3.8.
207+
2. Installing all dependencies in `requirements-dev.txt` from `tuf`.
208+
3. Install `marshmallow` with `pip install marshmallow`.
209+
210+
* Bad, because they use their custom types even for types existing in the
211+
standard `typing` module from python 3.6 onwards. This means that integrating
212+
`marshmallow` would make up for a bigger diff compared to `pydantic`.
213+
Additionally, because they define their types there could be problems specific
214+
to their types and conversion from-to standard types as defined in the `typing`
215+
python module.
216+
This was the case when I researched `marshmallow` and had to use the
217+
`marshmallow.fields.DateTime` class instead of the `datetime.datetime` object.
218+
219+
220+
176221
## Links
177222
* [in-toto ValidatorMixin](https://github.com/in-toto/in-toto/blob/74da7a/in_toto/models/common.py#L27-L40)
178223
* [ValidatorMixing usage](https://github.com/in-toto/in-toto/blob/74da7a/in_toto/models/layout.py#L420-L438)
179224
* [Pydantic documentation](https://pydantic-docs.helpmanual.io/)
225+
* [Marshmallow documentation](https://marshmallow.readthedocs.io/)
180226

181227
## Decision Outcome
182228

0 commit comments

Comments
 (0)