Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type serialization does not work inside valuesrules or valueschema #1511

Open
absassi opened this issue Aug 4, 2023 · 0 comments
Open

Type serialization does not work inside valuesrules or valueschema #1511

absassi opened this issue Aug 4, 2023 · 0 comments

Comments

@absassi
Copy link

absassi commented Aug 4, 2023

Cerberus 1.3 deprecates keyschema and valueschema in favor of keysrules and valuesrules. It also modifies any schema passed to it to rename the deprecated names with the corresponding new names.

However, Eve still uses valueschema in eve.methods.common.serialize (eve/methods/common.py line 523) and doesn't look for valuesrules. This means that if the domain configuration contains a valuesrules (or valueschema - it doesn't matter, because Cerberus renames them) with a type that requires conversion (such as datetime, for instance), that conversion will not happen.

Unfortunately, downgrading to Cerberus 1.2 is not an option for me, as it doesn't work in Python 3.11.


Expected Behavior

The following minimal example program and request should successfully insert a new document in the "example" collection:

from eve import Eve

app = Eve(
    settings={
        "DOMAIN": {
            "example": {
                "resource_methods": ["POST"],
                "schema": {
                    "field1": {
                        "type": "dict",
                        "valueschema": {"type": "datetime"},
                    },
                    "field2": {
                        "type": "dict",
                        "valuesrules": {"type": "datetime"},
                    },
                },
            },
        },
    })
app.run()
curl -XPOST -H 'Content-type: application/json' --data '{"field1": {"a": "Fri, 04 Aug 2023 12:26:15 GMT"}, "field2": {"a": "Fri, 04 Aug 2023 12:26:15 GMT"}}' http://localhost:5000/example

Actual Behavior

Eve does not convert the strings to datetime before passing them on to validation, as it would if the "type": "datetime" were not inside valuesrules. The request then fails with:

{"_status": "ERR", "_issues": {"field1": {"a": "must be of datetime type"}, "field2": {"a": "must be of datetime type"}}, "_error": {"code": 422, "message": "Insertion failure: 1 document(s) contain(s) error(s)"}}

Environment

  • Python version: 3.11
  • Eve version: 2.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant