Skip to content

Bug: API Gateway - invalid escape sequence '\[' #2980

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

Closed
nejcskofic opened this issue Aug 21, 2023 · 7 comments · Fixed by #2982
Closed

Bug: API Gateway - invalid escape sequence '\[' #2980

nejcskofic opened this issue Aug 21, 2023 · 7 comments · Fixed by #2982
Assignees
Labels
bug Something isn't working event_handlers

Comments

@nejcskofic
Copy link
Contributor

Expected Behaviour

When importing from aws_lambda_powertools.event_handler.api_gateway there should be no warning raised.

Current Behaviour

Deprecation warning is raised on import on api_gateway.pyL46:

DeprecationWarning: invalid escape sequence '\['
_UNSAFE_URI = "%<> \[\]{}|^"  # noqa: W605

If pytest is run with warnings as errors, Syntax error is raised instead and module loading is terminated.

Code snippet

import warnings


def test_api_gateway_import():
    with warnings.catch_warnings():
        warnings.simplefilter("error")
        from aws_lambda_powertools.event_handler.api_gateway import APIGatewayRestResolver

Possible Solution

Remove # noqa: W605 and prefix pattern with raw string modifier. I haven't checked if this is an issue elsewhere in the codebase.

Steps to Reproduce

  1. Remove __pycache__ from aws_lambda_powertools/event_handler (once code is bytecompiled error is no longer triggered)
  2. Run above code snippet as pytest test

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

PyPi

Debugging logs

No response

@nejcskofic nejcskofic added bug Something isn't working triage Pending triage from maintainers labels Aug 21, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 21, 2023

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

@rubenfonseca
Copy link
Contributor

Looking at this now

@rubenfonseca rubenfonseca self-assigned this Aug 21, 2023
@rubenfonseca
Copy link
Contributor

Thank you so much for the very very clear explanation of the problem, and the steps to reproduce! I'm opening a PR in a few minutes.

@rubenfonseca
Copy link
Contributor

@nejcskofic I've opened a PR to fix this, can you take a look to see if it makes sense?

@rubenfonseca rubenfonseca moved this from Triage to Working on it in Powertools for AWS Lambda (Python) Aug 21, 2023
@rubenfonseca rubenfonseca added event_handlers and removed triage Pending triage from maintainers labels Aug 21, 2023
@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (Python) Aug 21, 2023
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY 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 tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Aug 21, 2023
@nejcskofic
Copy link
Contributor Author

@rubenfonseca Looks good, thank you for the quick response!

@github-actions
Copy link
Contributor

This is now released under 2.23.1 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Aug 25, 2023
@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers
Projects
Status: Shipped
2 participants