Validation fails on tomlkit parsed data
frostming opened this issue · comments
When I try validating data parsed by tomlkit, it always fails. After some digging, the causes are as follows:
In cerberus/validator.py
:
def __init_processing(self, document, schema=None):
...
self.document = copy(document)
Calling copy on document
, which is a tomlkit.container.Container
instance, breaks the iterability for unknown reason:
>>> list(document)
['name', 'url', 'verify_ssl']
>>> list(copy(document))
[]
Therefore, all fields defined in the data will be recognized as missing.
I am not sure which of cerberus/tomlkit/plette
is responsible to fix this. But it will be easy to fix it here: just calls data.copy()
to pass to the validator.
Oops, I also saw this a couple of weeks ago, but forgot to raise it. You can work around the problem by changing line 25 below to explicitly copy to dict before validating:
plette/src/plette/models/base.py
Lines 16 to 27 in fad7956
if v.validate(dict(data), normalize=False):
...
This should be raised to TOMLkit to fix the copy
behaviour (it should work). The above patch should probably also be applied as well.
Edit: You also mentioned a similar workaround; sorry I missed that.