marshmallow-code / marshmallow-code/flask-marshmallow

How to get errors when using validate ?

Open
#142 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
887
Forks
65
Avg merge
7h 25m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named. Start by reproducing the supplied UserSchema.validate example with the listed marshmallow, flask-marshmallow, and SQLAlchemy versions, then inspect validation and partial-field behavior. Done means establishing whether missing fields should produce errors and documenting the correct behavior or a confirmed compatibility bug.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python, sqlalchemy
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.