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

fix: assertion of DynamoType failing #7073

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion moto/dynamodb/parsing/ast_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import abstractmethod
from collections import deque

from moto.dynamodb.models import DynamoType
from moto.dynamodb.models.dynamo_type import DynamoType
from ..exceptions import DuplicateUpdateExpression, TooManyAddClauses


Expand Down
50 changes: 50 additions & 0 deletions tests/test_dynamodb/test_dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
import uuid
import re
import importlib
import sys
from botocore.exceptions import ClientError
from datetime import datetime
from decimal import Decimal
Expand Down Expand Up @@ -5807,3 +5809,51 @@
ClientError, match="ProjectionExpression: Attribute name contains white space"
):
client.scan(TableName=table_name, ProjectionExpression="not_a_keyword, na me")


# https://github.com/getmoto/moto/pull/7073
def test_dynamo_type_assertion_exception_not_raised_when_reloading_modules():
importlib.reload(sys.modules["moto"])
to_reload = [module for module in sys.modules if module.startswith("moto.")]
for module in to_reload:
importlib.reload(sys.modules[module])

Check failure on line 5819 in tests/test_dynamodb/test_dynamodb.py

View workflow job for this annotation

GitHub Actions / test / test (3.7)

test_dynamo_type_assertion_exception_not_raised_when_reloading_modules TypeError: super(type, obj): obj must be an instance or subtype of type

importlib.reload(sys.modules["moto"])
to_reload = [module for module in sys.modules if module.startswith("moto.")]
for module in to_reload:
importlib.reload(sys.modules[module])

mock_dynamo = mock_dynamodb()
mock_dynamo.start()
dynamo_client = boto3.client("dynamodb")

Check failure on line 5828 in tests/test_dynamodb/test_dynamodb.py

View workflow job for this annotation

GitHub Actions / test / test (3.8)

test_dynamo_type_assertion_exception_not_raised_when_reloading_modules botocore.exceptions.NoRegionError: You must specify a region.

Check failure on line 5828 in tests/test_dynamodb/test_dynamodb.py

View workflow job for this annotation

GitHub Actions / test / test (3.9)

test_dynamo_type_assertion_exception_not_raised_when_reloading_modules botocore.exceptions.NoRegionError: You must specify a region.

Check failure on line 5828 in tests/test_dynamodb/test_dynamodb.py

View workflow job for this annotation

GitHub Actions / test / test (3.12)

test_dynamo_type_assertion_exception_not_raised_when_reloading_modules botocore.exceptions.NoRegionError: You must specify a region.

Check failure on line 5828 in tests/test_dynamodb/test_dynamodb.py

View workflow job for this annotation

GitHub Actions / test / test (3.11)

test_dynamo_type_assertion_exception_not_raised_when_reloading_modules botocore.exceptions.NoRegionError: You must specify a region.

Check failure on line 5828 in tests/test_dynamodb/test_dynamodb.py

View workflow job for this annotation

GitHub Actions / test / test (3.10)

test_dynamo_type_assertion_exception_not_raised_when_reloading_modules botocore.exceptions.NoRegionError: You must specify a region.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our CI does not have a region configured, so we have to specify it here explicitly

dynamo_client.create_table(
TableName="SomeTable",
AttributeDefinitions=[
{"AttributeName": "SomeKey", "AttributeType": "S"},
],
KeySchema=[
{"AttributeName": "SomeKey", "KeyType": "HASH"},
],
BillingMode="PAY_PER_REQUEST",
)

config_key = "SomeKeyValue"

dynamo_client.put_item(
TableName="SomeTable",
Item={
"SomeKey": {"S": config_key},
"ConfigValue": {"M": {"Some key": {"S": "Some value"}}},
},
)

dynamo_client.update_item(
TableName="SomeTable",
Key={
"SomeKey": {"S": config_key},
},
UpdateExpression="SET SomeValue = :some_value",
ExpressionAttributeValues={
":some_value": {"M": {"Some key": {"S": "Some new value"}}}
},
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Loading