question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE REQUEST] Return pydantic model directly and skip validation

See original GitHub issue

Hi,

Is there any way to return pydantic models directly, or to skip the validation?

I tend to do something like

@v.get('/echo')
@api.validate(query=m.EchoReq, resp=Response(HTTP_200=m.EchoRes), tags=['example'])
def echo():
    """Replies with the queried text value"""
    message = request.context.query.text
    result = m.EchoRes(result=message)
    return result.json()

This doesn’t play nicely with pydantic alias-es though.

I think the issue is that my model returns the real name and then the spectree validation fails since pydantic expected the alias name.

Can I skip the validation part but keep the route-to-model association for the doc generation?

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kemingycommented, Jul 20, 2021

Would this be a feature you would consider if I submit a PR?

Yeah, sure.

0reactions
kemingycommented, Sep 20, 2021

Hi, just to let you know I still intend on doing this - I just haven’t had the time yet.

Sure. Take your time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to skip validation in ORM mode? #1212 - GitHub
There is documentation for the construct classmethod that is much faster due to bypassing validation. I am now wondering if a similar thing ......
Read more >
Pydantic V2 Plan
pydantic -core operates on a tree of validators with no "model" type required at the base of that tree. It can therefore validate...
Read more >
How to Validate Your Data with Custom Validators of Pydantic ...
First, let's create a standard pydantic model and use the default validators to validate and normalize our data. A pydantic model is simply ......
Read more >
How we validate input data using pydantic
Pydantic raises a ValidationError when the validation of the model fails, stating which field, i.e. attribute, raised the error and why. In this ......
Read more >
Validators - pydantic
Custom validation and complex relationships between objects can be achieved using the validator decorator. Python 3.7 and above. from pydantic import BaseModel ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found