You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, first off, thanks for writing and maintaining this library!
The code below shows a very basic jsonmodel with two different permutations of required and nullable for BaseField.
The two problems are:
nullable is not properly enforced - even if a field is not required, it should be possible to deny null values. (required=false, nullable=False).
It seems impossible to enforce the existence of a value, but still allow nulls. (required=True, nullable=True).
I looked through the documentation and examples, and couldn't find a way to achieve these two goals, although I could have missed something.
Example (tested with jsonmodels 2.5.1):
from jsonmodels import models, fields, errors, validators
# Problem 1: Nullable is not enforced
class Foo(models.Base):
bar = fields.IntField(required=False, nullable=False)
Foo(bar=None) # This should fail because nullable=False, but instead this passes validation.
# Problem 2: It's impossible to enforce { foo: null } as a valid value.
class Foo(models.Base):
bar = fields.IntField(required=True, nullable=True)
Foo(bar=None) # This fails validation with Field is required!, but should succeed because nullable=True.
Also, there doesn't appear to be much documentation on nullable.
The text was updated successfully, but these errors were encountered:
Just to add to this - if the jsonmodel is used to produce a jsonschema, and that schema is used to validate json, then nullable does have an effect: if nullable is False, null values in the json will throw an error. So it seems that this behavior is inconsistent between the jsonschema the jsonmodel creates and the jsonmodel's own expectations.
Hi, first off, thanks for writing and maintaining this library!
The code below shows a very basic jsonmodel with two different permutations of
required
andnullable
forBaseField
.The two problems are:
nullable
is not properly enforced - even if a field is not required, it should be possible to deny null values. (required=false, nullable=False
).required=True, nullable=True
).I looked through the documentation and examples, and couldn't find a way to achieve these two goals, although I could have missed something.
Example (tested with
jsonmodels
2.5.1):Also, there doesn't appear to be much documentation on
nullable
.The text was updated successfully, but these errors were encountered: