0

I am using SQLAlchemyAutoSchema to automatically generate fields for the model, by default, it sets all fields' required status to False. How can I make all fields required?

class ReferralOuctomeSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = my_model
        dump_only = ("id",)
        required = True
davidism
  • 121,510
  • 29
  • 395
  • 339
Ayaz49
  • 325
  • 2
  • 4
  • 18
  • Can't you just make those fields `nullable=False` in SQLAlchemy? – Jérôme Nov 04 '22 at 08:16
  • Doesn't apply in this. I just want to apply it on the schema level. – Ayaz49 Nov 04 '22 at 12:13
  • 1
    I don't think there's any marshmallow feature to achieve this. You could iterate on the schema fields and set required. If you don't want to do it manually, it might be achievable with a custom metaclass as a base schema. You may also monkeypatch `Field._validate_missing` (but this sucks). – Jérôme Nov 04 '22 at 13:46

0 Answers0