Skip to content

Error calling decorated function from another decorated function #32

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
to-mc opened this issue May 15, 2020 · 4 comments
Closed

Error calling decorated function from another decorated function #32

to-mc opened this issue May 15, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@to-mc
Copy link
Contributor

to-mc commented May 15, 2020

When decorating multiple functions with Tracer.capture_method(), a RuntimeError is thrown if one of those methods contains a call to the other as it tries to run an event loop which is already running.

The offending code is here: https://github.com/awslabs/aws-lambda-powertools/blob/develop/python/aws_lambda_powertools/tracing/tracer.py#L454

To reproduce:

import json
from aws_lambda_powertools.tracing import Tracer

tracer = Tracer()


@tracer.capture_method
def func_1():
    return 1

@tracer.capture_method
def func_2():
    return 2

@tracer.capture_method
def sums_values():
    return func_1() + func_2()  # Calling a decorated function from another decorated function causes an error.

def lambda_handler(event, context):
    val = sums_values()

    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": val,
        }),
    }

@heitorlessa heitorlessa self-assigned this May 15, 2020
@heitorlessa heitorlessa added the bug Something isn't working label May 15, 2020
@heitorlessa
Copy link
Contributor

Thanks for reporting it Tom!

I created a test and reproduced it successfully. I couldn't find a reliable fix for that yet - I'll keep on trying and report back once I have some any good news

@heitorlessa
Copy link
Contributor

Got it working now - I'll publish a patch in the next hour or so. need to do some tidying first

image

@heitorlessa
Copy link
Contributor

hey Tom @cakepietoast - Could you try 0.9.3 and let me know if that's also successful from your end?

Tests passed, and also tested with a deployed Lambda fn using the same code - just want to be triple sure before I commit to CHANGELOG.

@to-mc
Copy link
Contributor Author

to-mc commented May 16, 2020

@heitorlessa working fine now, thanks for the quick fix!

@to-mc to-mc closed this as completed May 16, 2020
heitorlessa added a commit that referenced this issue May 16, 2020
* develop: (21 commits)
  bugfix: #32 Runtime Error for nested sync fns
  chore: renamed history to changelog dependabot
  bugfix: resolves #31 aiohttp lazy import
  chore: grammar issues
  improv: add project tenets
  Improv tracer - async support, patch, test coverage and X-Ray escape hatch (#29)
  Bugfix: "per second" metric units (#27)
  fix: #24 correct example test and docs
  chore: bump example to use 0.8.0 features
  Adopt logging best practices (#23)
  Decorator factory Feat: Create your own middleware (#17)
  chore: clean up CI workflows
  fix: CI attempt 4
  fix: CI attempt 3
  fix: CI attempt 3
  fix: CI attempt 2
  feat: add docs to CI
  chore: fix github badge typo
  chore: pypi monthly download badge
  fix: add missing single_metric example; test var name
  ...
heitorlessa referenced this issue in heitorlessa/aws-lambda-powertools-python Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

2 participants