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

Fix Flask status code processing after release 1.2.2 #341

Merged
merged 9 commits into from
Sep 22, 2023

Conversation

AndreiDrang
Copy link
Contributor

@AndreiDrang AndreiDrang commented Sep 21, 2023

Following the release of version 1.2.2, the server response's status code generated through "make_response" is no longer being processed accurately. Instead, it is being overwritten with the status code 200.

@AndreiDrang AndreiDrang changed the title Fix flask status code processing after release 1.2.2 Fix Flask status code processing after release 1.2.2 Sep 21, 2023
@AndreiDrang
Copy link
Contributor Author

Demo example:

from uuid import uuid4
from datetime import timedelta

from flask import Flask, make_response
from pydantic import Field, BaseModel, constr
from spectree import Response, SpecTree

AUTH_COOKIES_CONFIG = {
    "domain": None,
    "secure": False,
    "httponly": False,
    "samesite": None,
    "max_age": timedelta(days=10),
}


class Profile(BaseModel):
    name: constr(min_length=2, max_length=40)  # constrained str
    age: int = Field(..., gt=0, lt=150, description="user age(Human)")

    class Config:
        schema_extra = {
            # provide an example
            "example": {
                "name": "very_important_user",
                "age": 42,
            }
        }


class Message(BaseModel):
    text: str


app = Flask(__name__)
spec = SpecTree(path="docs", backend_name="flask")


@app.route("/api/user", methods=["POST"])
@spec.validate(json=Profile, resp=Response(HTTP_201=Message, HTTP_403=None), tags=["api"])
def user_profile():
    """
    verify user profile (summary of this endpoint)

    user's name, user's age, ... (long description)
    """
    response = make_response(Message(text="it works!").dict(), 201)
    response.set_cookie(
        key="auth_token",
        value=str(uuid4()),
        **AUTH_COOKIES_CONFIG,
    )
    return response


if __name__ == "__main__":
    spec.register(app)  # if you don't register in api init step
    app.run(port=8000)

Copy link
Member

@kemingy kemingy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! 🎉

I will figure out the pypy test failure later.

@kemingy kemingy merged commit 0977c39 into 0b01001001:master Sep 22, 2023
7 of 8 checks passed
@AndreiDrang
Copy link
Contributor Author

@kemingy
Hi
I think we need rollback to 1.2.1 version or smth like this. Cause after 1.2.2 release make_response additional logic(like set_cookies\headers and etc.) stop working and need some time to fix it.

@kemingy
Copy link
Member

kemingy commented Sep 22, 2023

@kemingy Hi I think we need rollback to 1.2.1 version or smth like this. Cause after 1.2.2 release make_response additional logic(like set_cookies\headers and etc.) stop working and need some time to fix it.

cc @jean-edouard-boulanger

Let me figure out. Thanks for your feedback.

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 this pull request may close these issues.

2 participants