marshmallow-code / marshmallow-code/marshmallow

Suggestion: Refactor builtin fields to expose validators for re-use

Open
#760 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactor
Dominant language
Python
Stars
7.2k
Forks
738
Avg merge
1d 23h
Merged PRs (30d)
7

Description

For my use case, I want to have a custom field-getter using `fields.Function()` but the value it gets will be a UUID. I'd like to be able to have the same validation as the builtin `fields.UUID()`. However, that doesn't seem to be [available in the `validate` module.](https://github.com/marshmallow-code/marshmallow/blob/dev/marshmallow/validate.py)

My suggestion is to refactor all the builtin field types so that they call validators in `validate`. That way, the same validators would also be exposed for reuse in custom user-defined fields.

As I'm imagining this, it would be a fully backwards-compatible change and the only difference to the public interface would be documenting/exposing new validators.

If that sounds like a good idea to the maintainers, I'm happy to take a crack at this and open a PR.

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

Start with marshmallow/validate.py and the implementations of fields.Function() and fields.UUID(), then compare how builtin field types currently perform validation. Define the reusable-validator scope and check that builtin behavior remains unchanged while validators are exposed for custom fields; confirm the public interface and documentation reflect the new exports.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.