Code Monkey home page Code Monkey logo

Comments (15)

sthulb avatar sthulb commented on September 14, 2024 1

@DariusKunce Confirmed! We'll add this into the next sprint to fix

def test_weird_issue():
    # GIVEN a Http API V2 proxy type event
    app = APIGatewayRestResolver(enable_validation=True)

    class FunkyTown(BaseModel):
        parameter: str

    @app.get("/my/path")
    def my_path(
        parameter: Annotated[str | None, Query(alias="parameter1")] = None,
    ) -> Response[FunkyTown]:
        assert isinstance(app.current_event, APIGatewayProxyEvent)

        assert parameter == "value"
        return Response(200, content_types.APPLICATION_JSON, FunkyTown(parameter=parameter))

    result = app(load_event("apiGatewayProxyEvent.json"), {})

    print(result)
    assert result["statusCode"] == 200

from powertools-lambda-python.

jpoissant avatar jpoissant commented on September 14, 2024 1

The issue isn't related to the alias but the fact that the openapi_validation.py handles all query strings with _normalize_multi_query_string_with_param and takes the first value of the item.

With "queryStringParameters": { "productType": "Category1" } it's normalize to: "productType": "C"

With "multiValueQueryStringParameters": { "productType": ["Category1"] } it's normalize correctly to: "productType": "Category1"

I was able to find this as I was trying to validate the min length of a query string parameter (def get_hello(fname: Annotated[Optional[str], Query(min_length=4)] = None) -> HelloWorld: and fname was always too short... as it was always truncated to 1 character.

The line truncating the value is here

from powertools-lambda-python.

boring-cyborg avatar boring-cyborg commented on September 14, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

from powertools-lambda-python.

sthulb avatar sthulb commented on September 14, 2024

Hi @DariusKunce this is on my list for verification tomorrow, thanks for submitting it!

from powertools-lambda-python.

heitorlessa avatar heitorlessa commented on September 14, 2024

@DariusKunce we're aiming to make a release tomorrow with this fix ahead of schedule -- let us know if you're blocked by this and we can make it today.

from powertools-lambda-python.

heitorlessa avatar heitorlessa commented on September 14, 2024

Thanks a lot for the timely comment @jpoissant.

@rubenfonseca i think we had mixed messaging and this wasn't fixed -- if you can't look into it tomorrow morning before release, let me know pretty plz

from powertools-lambda-python.

rubenfonseca avatar rubenfonseca commented on September 14, 2024

Thank you so much @jpoissant I'm looking at this right now

from powertools-lambda-python.

rubenfonseca avatar rubenfonseca commented on September 14, 2024

The issue isn't related to the alias but the fact that the openapi_validation.py handles all query strings with _normalize_multi_query_string_with_param and takes the first value of the item.

With "queryStringParameters": { "productType": "Category1" } it's normalize to: "productType": "C"

With "multiValueQueryStringParameters": { "productType": ["Category1"] } it's normalize correctly to: "productType": "Category1"

@jpoissant I need to understand the problem a little bit better, since I'm unable to reproduce the problem. Can you please confirm which event handler are you using? Is it the APIGatewayRestResolver ?

Reason I'm asking is that the REST API Gateway will always send multiValueQueryStringParameters, so the existing code already works correctly.

So I need to understand what scenario do you have where you only have queryStringParameters. Can you please clarify?

from powertools-lambda-python.

jpoissant avatar jpoissant commented on September 14, 2024

@rubenfonseca I am using the APIGatewayHttpResolver resolver. I just tried with the APIGatewayRestResolver and it work. So the bug is only related to the API Gateway v2 proxy payload format

from powertools-lambda-python.

jpoissant avatar jpoissant commented on September 14, 2024

@rubenfonseca would it be better to open a new bug for the APIGatewayHttpResolver resolver?

from powertools-lambda-python.

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.