marshmallow-code / marshmallow-code/marshmallow
Default error messages not getting overridden
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 738
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
I'm trying to add a customized error message for a class field in Marshamallow's schema. The field representation looks like this:
```
phone_number = fields.String(validate=Length(max=20), error_messages={'invalid': 'Phone number must be a string shorter than 20 letters.'})
```
When loading the request data to a schema with a longer phone number like:
```
try:
request_data = EditInvestorSchema().load(request.json)
except ValidationError as error:
return get_response(400, list(error.messages.values())[0])
```
The default error message "Longer than maximum length 20." arises instead of the customized error message.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the schema load using fields.String, Length(max=20), and the custom error_messages shown in the issue. Inspect how validation errors from Length are converted into ValidationError messages; done means an overlong phone number produces the customized message instead of the default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100