Git Product home page Git Product logo

moto-issue-demo's Introduction

moto-issue-demo

Repro instructions

$ git clone https://github.com/windhamg/moto-issue-demo.git
$ cd moto-issue-demo
$ poetry install
$ poetry run pytest -vvv

Output

        try:
            order_breakfast()
        except BaseException as err:
>           assert 'Item' in err.response
E           AssertionError: assert 'Item' in {'Error': {'Code': 'ConditionalCheckFailedException', 'Message': 'The conditional request failed'}, 'ResponseMetadata': {'HTTPHeaders': {'content-type': 'application/json', 'x-amzn-errortype': 'ConditionalCheckFailedException'}, 'HTTPStatusCode': 400, 'RetryAttempts': 0}, 'message': 'The conditional request failed'}
E            +  where {'Error': {'Code': 'ConditionalCheckFailedException', 'Message': 'The conditional request failed'}, 'ResponseMetadata': {'HTTPHeaders': {'content-type': 'application/json', 'x-amzn-errortype': 'ConditionalCheckFailedException'}, 'HTTPStatusCode': 400, 'RetryAttempts': 0}, 'message': 'The conditional request failed'} = ConditionalCheckFailedException('An error occurred (ConditionalCheckFailedException) when calling the UpdateItem operation: The conditional request failed').response

tests/test_order_breakfast.py:40: AssertionError
========================================================================= short test summary info ==========================================================================
FAILED tests/test_order_breakfast.py::test_breakfast_order - AssertionError: assert 'Item' in {'Error': {'Code': 'ConditionalCheckFailedException', 'Message': 'The conditional request failed'}, 'ResponseMetadata': {'HTTPHeaders'...
============================================================================ 1 failed in 0.42s =============================================================================

What's the problem?

With DynamoDB+boto3, when an update_item operation fails due to a ConditionExpression failing, AND we've set ReturnValuesOnConditionCheckFailure="ALL_OLD", we should see the current item in the error response.

For example, if we ran order-breakfast when hitting DynamoDB for real, here's the output of catching the exception and pprinting ex.response:

{
    'Error': {
        'Code': 'ConditionalCheckFailedException',
        'Message': 'The conditional request failed'
    },
    'Item': {
        'customer': {
            'S': 'mark'
        },
        'lock': {
            'M': {
                'acquired_at': {
                    'N': '123'
                }
            }
        },
        'mealtime': {
            'S': 'breakfast'
        }
    },
    'ResponseMetadata': {
        'HTTPHeaders': {
            'connection': 'keep-alive',
            'content-length': '223',
            'content-type': 'application/x-amz-json-1.0',
            'date': 'Mon, 23 Oct 2023 23:20:42 GMT',
            'server': 'Server',
            'x-amz-crc32': '3895319109',
            'x-amzn-requestid': '7RVFJQ170IU2JEIGB6VFNN73R7VV4KQNSO5AEMVJF66Q9ASUAAJG'
        },
        'HTTPStatusCode': 400,
        'RequestId': '7RVFJQ170IU2JEIGB6VFNN73R7VV4KQNSO5AEMVJF66Q9ASUAAJG',
        'RetryAttempts': 0
    }
}

Note that we see, Error, Item, and ResponseMetadata.

Under moto3, we do not see Item:

{
    'Error': {
        'Code': 'ConditionalCheckFailedException',
        'Message': 'The conditional request failed'
    },
    'ResponseMetadata': {
        'HTTPHeaders': {
            'content-type': 'application/json',
            'x-amzn-errortype': 'ConditionalCheckFailedException'
        },
        'HTTPStatusCode': 400,
        'RetryAttempts': 0
    },
    'message': 'The conditional request failed'
}

moto-issue-demo's People

Contributors

magicmark avatar windhamg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.