openergy / omemdb

A python in-memory relational database.
Mozilla Public License 2.0
0 stars 1 forks source link

Error message #6

Open Lefort-Antoine opened 1 year ago

Lefort-Antoine commented 1 year ago

Hy,

How can we adress error message ? This synthaxe is not working :

adress = fields.String(required=True, error_messages=dict( message="Adress is required", code=100 ) )

Regards

Lefort-Antoine commented 1 year ago

Found a way.

mydb.myrecodtable._dev_schema._declared_fields["adress"].error_messages["message"]

ccruveiller commented 3 months ago

Hi, if you want to customize error messages, you can override it as such:

        insee = fields.String(
            required=True,
            error_messages={
                "required": "Insee is a required field."
            }

I'd recommend this way if it is only a specific field used once, if you want to customize a field you could create your own field instance

maximeepaulais commented 2 months ago

Hi,

I try to customize my error message with a range validation via validate

    left_cantilever = fields.Float(required=False,
                                   load_default=None,
                                   allow_none=True,
                                   validate=validate.Range(min=0.5, min_strict=False, error="left_cantilever_error"),
                                   )

Unfortunaltely, I do not get back my custom message. I get back : "given value (0.3) does not respect range conditions." Do you know how i could customize my message when doing a range validation ?