marshmallow-code / marshmallow-code/marshmallow-sqlalchemy

Don't set a field as required if it's read-only

Open
#672 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
580
Forks
101
Avg merge
7h 6m
Merged PRs (30d)
3

Description

This line shows that fields' `required` flag will only depend on whether they are nullable and have a default value:

https://github.com/marshmallow-code/marshmallow-sqlalchemy/blob/3754933b49554e6b7aa0ce282b43befb730dd7b2/src/marshmallow_sqlalchemy/convert.py#L427

But we're running into cases where certain fields (eg relations for which we want to enforce loading through the foreign key, but still want dumping the whole nested schema) are marked as `required` even though they are also `dump_only`.

Any reason for not including `not dump_only` as a condition for marking as `required`?

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 at src/marshmallow_sqlalchemy/convert.py line 427 and trace how nullable, default values, and dump_only determine the required flag. Confirm that dump-only fields, including the relationship case described in the issue, are not marked required; the issue is complete when the generated schema reflects that behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.