Skip to content

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

@VassilisPallas

Description

@VassilisPallas

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 ============================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions