Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get errors when using validate ? #142

Open
JulieRossi opened this issue Jul 28, 2019 · 1 comment
Open

How to get errors when using validate ? #142

JulieRossi opened this issue Jul 28, 2019 · 1 comment

Comments

@JulieRossi
Copy link

Hi !

I am using flask-marshmallow for the first time and the lib looks great but I don't get what I am supposed to do to get an error when I try to validate an element with a missing field.

Here's a simplified version of the code :

from flask import Flask
from flask_marshmallow import Marshmallow

app = Flask(__name__)
ma = Marshmallow(app)
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)

class UserSchema(ma.Schema):
    class Meta:
        fields = ("id", "name")

user_schema = UserSchema()

print(user_schema.validate({}, partial=False))

This outputs {} while I would expect it to return an object listing errors.
(Just in case, I also tried with partial=True and partial=('id',), and I also tried to set the partial values at different places (schema definition and schema instanciation) but I get the same result)

Could you please advice on what I am doing wrong ?

For information, here are the versions I use :

marshmallow==3.0.0rc8
marshmallow-sqlalchemy==0.17.0
flask-marshmallow==0.10.1
Flask-SQLAlchemy==2.4.0
SQLAlchemy==1.3.6

@sjokkateer
Copy link

Initialize the SQLAlchemy and Marshmallow extensions, in that order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants