fix: assertion of DynamoType failing#7073
Conversation
bblommers
left a comment
There was a problem hiding this comment.
That's odd - and must have been fun to debug!
This is definitely something that would need a test case though, just to prevent us from ever re-introducing the bug by accident.
Just out of interest - can it be reproduced by using the manual mocks?
m = mock_dynamodb().
m.start().
..
m.stop()
# reloading magic
m.start()
m.stop()
If so, that would mean the fix could be verified in a single test.
681e1d5 to
d6b0e16
Compare
|
@bblommers "fun to debug!" is certainly one way to put it 😅 I have added a self-contained test which reproduces the issue using the style you've suggested. |
tests/test_dynamodb/test_dynamodb.py
Outdated
|
|
||
| mock_dynamo = mock_dynamodb() | ||
| mock_dynamo.start() | ||
| dynamo_client = boto3.client("dynamodb") |
There was a problem hiding this comment.
Our CI does not have a region configured, so we have to specify it here explicitly
| ExpressionAttributeValues={ | ||
| ":some_value": {"M": {"Some key": {"S": "Some new value"}}} | ||
| }, | ||
| ) |
There was a problem hiding this comment.
We should stop the mock at the end:
mock_dynamo.stop()
Not a big problem if you only run the one test, but if you run multiple tests and one mock is still active, it wreaks havoc.
|
Hmm.. Our CI still doesn't seem to like that. All the tests after the new tests are now failing: |
This is a complete test which reproduces the issue.
The
reloadfunction is sourced from this Stack Overflow response. Our tests currently rely on this behaviour. The use of this function contributes to the occurrence of this bug.Running the above code results in this assertion failing:
moto/moto/dynamodb/parsing/ast_nodes.py
Line 330 in bfac8a8
It seems something along the lines of this is going on: the
reloadfunction combined with the inconsistent imports means two different instances ofDynamoTypecoexist and are in use.Because the
reloadfunction is called between test invocations, this error only occurs when more than one test runs in a single pytest execution. So with the example above, running each case individually they'll both pass.If appropriate, I can add the example above as a test here.