Coder Social home page Coder Social logo

Comments (6)

kemingy avatar kemingy commented on June 4, 2024 1

I agree that spectree should not modify what the view returns (when it's already a valid response). This change is due to that the response might be a BaseModel which is not a valid JSON body. Will fix this later.

from spectree.

kemingy avatar kemingy commented on June 4, 2024

Hi, I checked the code diff but didn't find the related commit. This sounds like something related to the pydantic.BaseModel.dict(by_alias=True). Ref https://docs.pydantic.dev/1.10/usage/exporting_models/#modeldict

It might also related to the way you return the response. May I know which framework (flask/falcon/starllete) are you using? How you return the response in your handler?

from spectree.

divad avatar divad commented on June 4, 2024

We use Flask. As for the how we return, we just return a plain dictionary

return {'this': 'that', 'schema': 'this'}

(this isn't the real code, but I'm not allowed to copy/paste that, but that's how it works)

from spectree.

divad avatar divad commented on June 4, 2024

We suspect this might be the change that caused it: https://github.com/0b01001001/spectree/pull/345/files#diff-f960f6fbc43bc13c5e859d015690fc19c196f60b76ff5be61fbb0a3e26eea260R173

from spectree.

divad avatar divad commented on June 4, 2024

Right, yes, so. Previously spectree's behavior was to return the response the view provided. It did check that the response was valid according to the model, but it otherwise returned it unaltered. 1.2.4 changed spectree's behavior to return the result of validating the response, rather than the response. pydantic can change types and even names (as this bug shows), and so by returning the result of the validation the wrong thing is returned.

I believe this is a regression, and in my opinion spectree should not modify what the view returns, it should only check it against the validator. I suggest a new release on the 1.2.x series returning to the pre 1.2.4 behavior and also release a 1.3.x with the altered behavior, and perhaps with a "return_response_unaltered" flag. That way folks know, via semver, that 1.3.x changes spectree's behavior.

from spectree.

divad avatar divad commented on June 4, 2024

many thanks 🙌

also apologies, I feel I came off as rude in this ticket, that was not my intention.

from spectree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.