Skip to content

Question: Why do validation errors raise InvalidMediaTypeValue? #175

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

Closed
berislavlopac opened this issue Dec 16, 2019 · 3 comments · Fixed by #191
Closed

Question: Why do validation errors raise InvalidMediaTypeValue? #175

berislavlopac opened this issue Dec 16, 2019 · 3 comments · Fixed by #191

Comments

@berislavlopac
Copy link

I have noticed that, when sending an incorrect request (e.g. an object with a string where a number is expected), MediaType.cast and MediaType.unmarshal will raise InvalidMediaTypeValue in all cases, which is actually misleading: the media type is correct (e.g. application/json), but the validation raises an incorrect error. Was that on purpose?

@p1c2u
Copy link
Collaborator

p1c2u commented Jan 13, 2020

Hi @berislavlopac
media type itself is correct but passed value (schema) is incorrect, isn't it? I called the general exceptions for media type value errors as InvalidMediaTypeValue but if you think it's misleading I'm open for naming suggestions.

@berislavlopac
Copy link
Author

Yes, I think it's confusing. For example. MediaType.cast has this block:

        try:
            return self.schema.cast(deserialized)
        except CastError as exc:
            raise InvalidMediaTypeValue(exc)

I think that wrapping the CastError inside a media type exception is confusing, as the same problem can happen when a validation is triggered from other places, not just from MediaType. In any case, it seems to me that the exact chain of errors gets lost in this pattern; perhaps it might help to raise using from to preserve the chain?

@p1c2u
Copy link
Collaborator

p1c2u commented Feb 2, 2020

I can't use from because it's not supported in Python 2 that's why CastError is wrapped inside a media type exception. The plan is to move cast outside of schema models and get rid of media type and parameters exception wrapping.

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

Successfully merging a pull request may close this issue.

2 participants