I have the following data:
data={
'last_visit':datetime.datetime(2020, 9, 30, 11, 12, 24, 512347)
}
The schema is based on the model:
class ModelSchema(db_schema.SQLAlchemyAutoSchema):
class Meta:
model = UserModel
and the model itself:
class UserModel(db.Model, AllFeaturesMixin):
last_visit= db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
When I do validation, I have an error:
> schema.validate(self.data)
> {'last_visit': ['Not a valid datetime.']}
Not sure why.
validate()
should be called on the raw data fromflask.request.get_json()
or equivalent. What you are looking for is the raw results of deserialization from something likejson.loads()
. With this raw dictionarylast_visit
is still a string, and is what marshmallow DateTime field is expecting (a formatted datetime string).Below is a basic example: