aws / aws-sam-cli-app-templates

Apache License 2.0
486 stars 260 forks source link

Bug: Argument missing for parameter "context" in `hello_world/app.py` #499

Closed ChrisHills463 closed 7 months ago

ChrisHills463 commented 7 months ago

Description:

When installing the sample hello-world app, there is a type error reported in hello_world/app.py

Steps to reproduce:

Install pyright or any other Python type checker Install aws-lambda-powertools with pip Run the following commands

sam init --app-template hello-world-powertools-python --name sam-app --package-type Zip --runtime python3.11 --no-tracing
pyright sam-app/hello_world/app.py

Observed result:

[..]/sam-app/hello_world/app.py
  [..]/sam-app/hello_world/app.py/hello_world/app.py:32:2 - error: Argument missing for parameter "context" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 informations 

Expected result:

No errors reported.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Fedora 38
  2. If using SAM CLI, sam --version: 1.114
  3. AWS region: N/A
lucashuy commented 7 months ago

The linting error looks like its being raised when the metrics publisher decorator is used: https://github.com/aws/aws-sam-cli-app-templates/blob/ccd6c098c35880495d6dd5a1b710a20831c62791/python3.11/hello-pt/%7B%7B%20cookiecutter.project_name%20%7D%7D/hello_world/app.py#L59-L60

We don't actually maintain the powertools library, the best way forward to get the typing fixed would be to reach out to the Powertools team: https://github.com/aws-powertools/powertools-lambda-python to create an issue there.

In the meantime, it should be possible to ignore the linting issue for now with:

@metrics.log_metrics(capture_cold_start_metric=True) # pyright: ignore[reportGeneralTypeIssues]
ChrisHills463 commented 7 months ago

For anyone else finding this bug, I have spoken to the powertools team and they accepted a new bug report. Also worth noting is that the root issue appears to be with pyright, however it can be mitigated within the library.

mildaniel commented 7 months ago

Issue seems to be coming from Powertools, resolving.