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

[async] Check if args/kwargs are JSON Serializable while running locally #1791

Open
mariamrf opened this issue Feb 28, 2019 · 0 comments
Open

Comments

@mariamrf
Copy link

Context

  • When running an async @task locally, the args and kwargs are passed as they are (even if they're not JSON Serializable).
  • It would be nice to have this check when running locally so we can test for and predict failures of that kind.

Expected Behavior

  • When a @task is run locally with invalid args/kwargs (non-serializable), it should break/raise an exception as this is the actual behavior when it's deployed.

Actual Behavior

  • When a @task is run locally with invalid args/kwargs (non-serializable), it just runs as a normal function and therefore, we can't catch errors of this kind in the tests.

Possible Fix

In async.py:

            lambda_function_name = lambda_function_name_arg or os.environ.get('AWS_LAMBDA_FUNCTION_NAME')
            aws_region = aws_region_arg or os.environ.get('AWS_REGION')

            if (service in ASYNC_CLASSES) and (lambda_function_name):
                send_result = ASYNC_CLASSES[service](lambda_function_name=lambda_function_name,
                                                     aws_region=aws_region,
                                                     capture_response=capture_response).send(task_path, args, kwargs)
                return send_result
            else:
                validate_json_serializable({'args': args, 'kwargs': kwargs})
                return func(*args, **kwargs)

and in utilities.py:

def validate_json_serializable(thing):
    try:
        json.dumps(thing)
    except (TypeError, OverflowError):
        # raise more human-readable error here

Steps to Reproduce

  1. Write a function that accepts a non-serializable type (like an instance of a class)
  2. Run this function locally
  3. Function runs!
  4. Deploy the code to Lambda
  5. Function breaks

Your Environment

  • Zappa version used: 0.45.1
  • Operating System and Python version: 3.6
  • The output of pip freeze:
  • Link to your project (optional):
  • Your zappa_settings.py:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant