Skip to content

Commit

Permalink
test/alternator: check operation on invalid TableName
Browse files Browse the repository at this point in the history
Issue scylladb#12538 suggested that maybe Alternator shouldn't bother reporting an
invalid table name in item operations like PutItem, and that it's enough
to report that the table doesn't exist. But the test added in this patch
shows that DynamoDB, like Alternator, reports the invalid table name in
this case - not just that the table doesn't exist.

That should make us think twice before acting on issue scylladb#12538. If we do
what this issue recommended, this test will need to be fixed (e.g., to
accept as correct both types of errors).

Signed-off-by: Nadav Har'El <nyh@scylladb.com>
  • Loading branch information
nyh committed Jan 22, 2023
1 parent 0ff0c80 commit 1ded581
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/alternator/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ def test_item_operations_nonexistent_table(dynamodb):
dynamodb.meta.client.put_item(TableName='non_existent_table',
Item={'a':{'S':'b'}})

# DynamoDB documentation specifies that table names must be 3-255 characters,
# and match the regex [a-zA-Z0-9._-]+. If an item operation like PutItem
# is given a TableName not matching these rules, it would make sense to treat
# it as just another case of a non-existent table (ResourceNotFoundException),
# but it turns out that DynamoDB returns a ValidationError in that case.
# Saying for example that "Value 'non!existent!table' at 'tableName' failed
# to satisfy constraint: Member must satisfy regular expression pattern:
# [a-zA-Z0-9_.-]+".".
# This test suggests that issue #12538 should not be done.
def test_item_operations_improper_named_table(dynamodb):
with pytest.raises(ClientError, match='ValidationException'):
dynamodb.meta.client.put_item(TableName='non!existent!table',
Item={'a':{'S':'b'}})
with pytest.raises(ClientError, match='ValidationException'):
dynamodb.meta.client.put_item(TableName='xx',
Item={'a':{'S':'b'}})

# Fetching a non-existent item. According to the DynamoDB doc, "If there is no
# matching item, GetItem does not return any data and there will be no Item
# element in the response."
Expand Down

0 comments on commit 1ded581

Please sign in to comment.