Skip to content
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

Logger decorator does not accept more arguments than event and context #69

Closed
VassilisPallas opened this issue Dec 13, 2021 · 5 comments
Labels
Logger Logger utility Python

Comments

@VassilisPallas
Copy link

What were you trying to accomplish?

I'm trying to use the logger in a lambda function that is executed once we deploy it via Terraform. We pass some custom arguments, however, the decorator is not able to handle them.

Expected Behavior

The expected behaviour should be the decorator to shallow the extra arguments

Current Behavior

Lambda function is falling with the error TypeError: decorate() got an unexpected keyword argument 'argument_name'

Possible Solution

By appending variadic arguments to decorate function, ti should fix the problem.

Steps to Reproduce (for bugs)

It's similar to that error.

Environment

  • Powertools version used: 1.22.0
  • Packaging format (Layers, PyPi):
  • AWS Lambda function runtime:
  • Debugging logs

How to enable debug mode**

I caught it during testing, below is the exact error

===================================================================== FAILURES ======================================================================
__________________________________________________________ test_migration_handler_failure ___________________________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x11167cf90>
lambda_context = lambda_context.<locals>.LambdaContext(function_name='test', memory_limit_in_mb=128, invoked_function_arn='arn:aws:lambda:eu-west-1:809313241:function:test', aws_request_id='52fdfc07-2182-154f-163f-5f0f9a621d72')

    def test_migration_handler_failure(monkeypatch, lambda_context):
        mock_err_message = "Testing for failure"
    
        def _err_side_effect(*args):
            raise TypeError("Testing for failure")
    
        mock_command = MagicMock()
        mock_command.upgrade.side_effect = _err_side_effect
        monkeypatch.setattr("lambdas.database_migration.handlers.command", mock_command)
    
        mock_event = {}
    
>       result = migration_handler(mock_event, lambda_context, num_retries=3, timeout=0.5)
E       TypeError: decorate() got an unexpected keyword argument 'num_retries'

tests/database_migration/test_handler.py:37: TypeError
------- generated xml file: /Users/vspallas/Documents/Development/project/python_unit_tests_junit_report.xml -------
============================================================== short test summary info ==============================================================
FAILED tests/database_migration/test_handler.py::test_migration_handler_failure - TypeError: decorate() got an unexpected keyword argument 'num_re...
============================================================ 1 failed, 1 passed in 0.35s ============================================================
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 13, 2021

Thanks for opening your first issue here! We'll come back to you as soon as we can.

@heitorlessa
Copy link
Contributor

Hey @VassilisPallas if you have the bandwidth, feel free to send a PR for this quick fix and we can include it in the next release ASAP.

Otherwise we can tackle that later

heitorlessa referenced this issue in heitorlessa/aws-lambda-powertools-python Dec 20, 2021
@heitorlessa
Copy link
Contributor

done @VassilisPallas - it'll be available in today's release :)

@heitorlessa heitorlessa transferred this issue from aws-powertools/powertools-lambda-python Dec 20, 2021
@heitorlessa heitorlessa added Logger Logger utility Python labels Dec 20, 2021
@heitorlessa
Copy link
Contributor

hey @VassilisPallas this is now available as part of today's 1.23.0 release :) Thank you again for this feature request!

@VassilisPallas
Copy link
Author

Hey @heitorlessa, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Logger Logger utility Python
Projects
None yet
Development

No branches or pull requests

2 participants