Skip to content

Bug: Depends() and Request parameters with a None default are not resolved on Python 3.10 #8648

Closed

Description

@leandrodamascena

Expected Behaviour

A route or middleware parameter declared as d: Annotated[str, Depends(get_dep)] = None receives the resolved dependency, and request: Request = None receives the Request, on every supported Python version.

Current Behaviour

On Python 3.10 only, both parameters receive None. typing.get_type_hints on 3.10 wraps the annotation of a parameter whose default is None in Optional[...], so Annotated[str, Depends(...)] becomes Union[Annotated[str, Depends(...)], None]. _get_depends_from_annotation only checks get_origin(annotation) is Annotated, and _find_request_param_name only checks annotation is Request, so neither matches and the parameter falls back to its default. Python 3.11 stopped wrapping, which is why 3.11+ work. Present since Depends() shipped in v3.28.0.

Confirmed in real Lambda functions on python3.10 (layer and zip package) and locally with a 3.10 virtualenv.

Code snippet

from typing import Annotated
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Depends

app = APIGatewayRestResolver()

def get_region() -> str:
    return "eu-west-1"

@app.get("/my/path")
def handler(region: Annotated[str, Depends(get_region)] = None):
    return {"region": region}

# python 3.10: {"region": null}
# python 3.11+: {"region": "eu-west-1"}

Possible Solution

Unwrap Optional[X] / X | None before inspecting the annotation, in _get_depends_from_annotation, in the Request injection inside solve_dependencies, and in _find_request_param_name. A small helper _unwrap_optional that returns the single non-None arg of a Union covers all three. Tests with = None defaults fail on 3.10 today and pass with the change.

Steps to Reproduce

Run the snippet with Python 3.10 using tests/events/apiGatewayProxyEvent.json as the event.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

Lambda Layers, PyPi

Debugging logs

Activity

  1. powertools-for-aws-oss-automation commented on Oct 20, 2026

    @powertools-for-aws-oss-automation

    Warning

    This issue is now closed. Please be mindful that future comments are hard for our team to see.
    If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  2. added
    pending-releaseFix or implementation already in dev waiting to be released
    and removed
    triagePending triage from maintainers
    on Oct 20, 2026
  3. github-actions commented on Oct 22, 2026

    @github-actions
    Contributor

    This is now released under 3.37.0 version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions