Merge pull request #2908 from d-ryzhikov/fix/table-filter-value-error
Handle ValueError raised on missing table name
This commit is contained in:
commit
eb17288503
@ -92,16 +92,24 @@ class DynamoHandler(BaseResponse):
|
|||||||
def list_tables(self):
|
def list_tables(self):
|
||||||
body = self.body
|
body = self.body
|
||||||
limit = body.get("Limit", 100)
|
limit = body.get("Limit", 100)
|
||||||
if body.get("ExclusiveStartTableName"):
|
all_tables = list(self.dynamodb_backend.tables.keys())
|
||||||
last = body.get("ExclusiveStartTableName")
|
|
||||||
start = list(self.dynamodb_backend.tables.keys()).index(last) + 1
|
exclusive_start_table_name = body.get("ExclusiveStartTableName")
|
||||||
|
if exclusive_start_table_name:
|
||||||
|
try:
|
||||||
|
last_table_index = all_tables.index(exclusive_start_table_name)
|
||||||
|
except ValueError:
|
||||||
|
start = len(all_tables)
|
||||||
|
else:
|
||||||
|
start = last_table_index + 1
|
||||||
else:
|
else:
|
||||||
start = 0
|
start = 0
|
||||||
all_tables = list(self.dynamodb_backend.tables.keys())
|
|
||||||
if limit:
|
if limit:
|
||||||
tables = all_tables[start : start + limit]
|
tables = all_tables[start : start + limit]
|
||||||
else:
|
else:
|
||||||
tables = all_tables[start:]
|
tables = all_tables[start:]
|
||||||
|
|
||||||
response = {"TableNames": tables}
|
response = {"TableNames": tables}
|
||||||
if limit and len(all_tables) > start + limit:
|
if limit and len(all_tables) > start + limit:
|
||||||
response["LastEvaluatedTableName"] = tables[-1]
|
response["LastEvaluatedTableName"] = tables[-1]
|
||||||
|
@ -4277,3 +4277,12 @@ def test_update_expression_with_multiple_set_clauses_must_be_comma_separated():
|
|||||||
assert False, "Validation exception not thrown"
|
assert False, "Validation exception not thrown"
|
||||||
except dynamodb.exceptions.ClientError as e:
|
except dynamodb.exceptions.ClientError as e:
|
||||||
assert_raise_syntax_error(e, "Mystr2", "myNum Mystr2 myNum2")
|
assert_raise_syntax_error(e, "Mystr2", "myNum Mystr2 myNum2")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_list_tables_exclusive_start_table_name_empty():
|
||||||
|
client = boto3.client("dynamodb", region_name="us-east-1")
|
||||||
|
|
||||||
|
resp = client.list_tables(Limit=1, ExclusiveStartTableName="whatever")
|
||||||
|
|
||||||
|
len(resp["TableNames"]).should.equal(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user