aws-powertools / powertools-lambda

MIT No Attribution
73 stars 4 forks source link

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

Closed VassilisPallas closed 2 years ago

VassilisPallas commented 2 years ago

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

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[bot] commented 2 years ago

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

heitorlessa commented 2 years ago

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 commented 2 years ago

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

heitorlessa commented 2 years ago

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

VassilisPallas commented 2 years ago

Hey @heitorlessa, thanks for the quick fix!