Commit Graph

242 Commits

Author SHA1 Message Date
Brian Pandola
c1b38be02d
Add support for DynamoDB Backup/Restore (#3995)
* Add support for DynamoDB Backup/Restore

Basic support for the following endpoints has been implemented with full test coverage:
- create_backup
- delete_backup
- describe_backup
- list_backups
- restore_table_from_backup

Behavior and error messages verified against a real AWS backend.

* Refactor test based on PR feedback
2021-06-10 07:05:07 +01:00
Matthew Davis
d6384fcb35
Enforce dynamodb key size limit [solves #3866] (#3888)
* add tests for dynamodb max key size

correct too-large error for ddb key

* remove unnecessary requires_boto_gte decorator from ddb tests

* remove literal emoji from ddb test

* implement dynamodb key limits, WIP

* correct direction of dynamodb range key length check

* fix tests for dynamodb max key size check

* catch ddb validation errors and rethrow properly

* finish ddb key size limit fixes

* fix linting

* handle unicode in v2.7 tests

* fix encoding issue in py2.7 for ddb

* linting

* Python2/3 compatability

Co-authored-by: Bert Blommers <info@bertblommers.nl>
2021-04-30 13:47:47 +01:00
David Pedrosa
ba0f0bd513
Improve dynamodb query case sensitivity (#3799) (#3800)
* between clause is not case-sensitive anymore

* begins_with will raise an exception unless lower-case is used

Co-authored-by: David Pedrosa <d.pedrosa@indizen.com>
2021-03-25 20:22:36 +00:00
Ilya Konstantinov
0912abe5f6
dynamodb: fix deleting last set element (w/attr name) (#3708)
* dynamodb: deleting last set element

* add user-facing test
2021-02-19 07:47:51 +00:00
Brian Pandola
613b1395b8
Fix: DynamoDB:GetItem throws wrong error when table doesn't exist (#3700)
* Fix: DynamoDB:GetItem throws wrong error when table doesn't exist

* Use unique exception for table not found, per PR feedback

* Just fix the reported issue, without touching anything else...
2021-02-17 11:22:00 +00:00
Jonathan Bergknoff
676d61bf5b
Add CRC32 to DynamoDB responses (#3677)
* Add CRC32 to DynamoDB responses

* Change test assertion

* CRC32 - Align Py2/Py3 behaviour

Co-authored-by: Bert Blommers <info@bertblommers.nl>
2021-02-12 14:26:06 +00:00
Brian Pandola
cd044ef00b
Remove redundant test code (#3640)
These tests, when run, do not execute any `moto` code. They fail the
parameter validation check in `botocore`, which raises an exception
before ever sending a request.  These tests do not cover or verify
any `moto` behavior and have been removed.
2021-01-31 12:21:24 +00:00
Brian Pandola
640df04840
Implement Add to List for dynamodb:UpdateItem (#3585)
This handles the add-to-list case using the legacy `AttributeUpdates` parameter.

* Added test coverage.
* Verified against real AWS backend.

Closes #3561
2021-01-10 14:20:41 +00:00
Bert Blommers
e1fc3a9596
#3506 - DynamoDB - Allow StringSets to be passed to update_item() (#3519) 2020-12-07 09:31:53 +00:00
Garrett
9e3b23758a
[dynamodb2] Support include projection on indexes (#3498)
* [dynamodb2] Support include projection on indexes

* linter
2020-11-25 20:28:05 +00:00
Rich Unger
f045af7e0a
Add support for empty strings in non-key dynamo attributes (#3467)
* Add support for empty strings in non-key attributes

https://github.com/spulec/moto/issues/3339

* Nose, not pytest

* Revert "Nose, not pytest"

This reverts commit 5a3cf6c887dd9fafa49096c82cfa3a3b7f91d224.

* PUT is default action
2020-11-17 09:12:39 +00:00
Oide Brett
62d382ff70
Fixed issue 3448 for DynamoDB update_item (#3463)
* Fixed issue 3448 for DynamoDB update_item

* Tidied up fix for issue 3448 for DynamoDB update_item

* Reformatted fix for issue 3448 for DynamoDB update_item

* removed use of f-strings in test case as it fails in Travis CI build due to Python 2.7 support of f strings
2020-11-17 07:41:54 +00:00
gsamaras
d068653dea
dynamodb2 support for default Action ('Put') in update_item (#3454)
Co-authored-by: Georgios Samaras <gsamaras@amazon.com>
2020-11-14 11:10:38 +00:00
Bert Blommers
273ca63d59 Linting 2020-11-11 15:55:37 +00:00
Bert Blommers
cb6731f340 Convert fixtures/exceptions to Pytest 2020-11-11 15:54:01 +00:00
Matěj Cepl
5697ff87a8 Back to Black 2020-11-10 14:12:38 +01:00
Matěj Cepl
ea489bce6c Finish porting from nose to pytest. 2020-11-10 08:25:05 +01:00
Matěj Cepl
77dc60ea97 Port test suite from nose to pytest.
This just eliminates all errors on the tests collection. Elimination of
failures is left to the next commit.
2020-11-10 08:23:44 +01:00
Brian Pandola
2f23f6b26b
Fix dynamodb:TransactGetItems response for items that do not exist (#3420)
If the requested item has no projected attributes, the corresponding ItemResponse
object is an empty Map.[1]  Verified against real AWS.

Fix existing general test case and add an explicit test case to cover this scenario.

[1]: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html#API_TransactGetItems_ResponseElements

Fixes #3404
2020-10-29 11:50:45 +00:00
Brian Pandola
99556620a9
Fix: Empty sets not removed from item after UpdateExpression (#3386)
DynamoDB does not support empty sets. If the last item in a set is
deleted as part of an UpdateExpression, the attribute must be removed.

Ref: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html

Fixes #3296
2020-10-14 16:32:42 +01:00
Sarang Joshi
08da2c92d9
fix(dynamodb2): Fix update_item nested insert (#3355)
When comparing old and new values when doing a nested item update, the
`!=` implementation fails when the value being compared is `None`. This
results in an exception when trying to insert a new item into a nested
map. So just do a quick check that the original value is exists before
doing the comparison, as the `None` default is what is tripping this.
2020-10-05 13:40:33 +01:00
Iain Bullard
88a1134657
Fix DynamoDb2 ExpressionAttributeNames can start with a number (#3206)
When using pynamodb's support for transactions it makes use of of
ExpressionAttributeNames that look like #0 #1 etc. According to

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html

And when testing against dynamodb-local these work without issue,
however, when testing with moto they fail.
2020-07-31 17:46:48 +01:00
Mike Fogel
9072153474
Fix dynamodb2 KEYS_ONLY Indexes (#3125)
KEYS_ONLY indexes include table keys.
2020-07-14 13:42:13 +01:00
Bert Blommers
4e0d588307 DynamoDB - Allow ProjectionType to be set for LSIs 2020-07-03 14:20:04 +01:00
Bert Blommers
8a092c91ae DynamoDB - Add support for GSI's ProjectionType: KEYS_ONLY 2020-06-27 11:07:15 +01:00
Steve Pulec
1f2e6b8925
Merge pull request #3071 from bblommers/dynamodb_gsi_add_throughput
DynamoDB - Add default GSI throughput
2020-06-13 18:59:33 -05:00
Bert Blommers
bbe1320e7c DynamoDB - Add default GSI throughput 2020-06-13 20:27:05 +01:00
Bert Blommers
d21088699e Linting 2020-06-03 17:14:48 +01:00
Bert Blommers
b0da78c29d
Update test_dynamodb.py 2020-06-03 16:15:46 +01:00
Bert Blommers
9ca10e3630 #3046 - DynamoDB - Add Key-size Validation for BatchGetItem 2020-06-03 15:36:32 +01:00
Bert Blommers
48aa8ec3f9 #2985 - DynamoDB - TransactWriteItems - Fix error-type returned 2020-05-11 15:33:24 +01:00
Anton Grübel
65e790c4eb
Add dynamodb continuous backups (#2976)
* remove print statement

* Add dynamodb.describe_continuous_backups

* Add dynamodb.update_continuous_backups

* Fix Python 2 timestamp error
2020-05-08 15:57:48 +01:00
pvbouwel
9e7803dc36
[Bugfix] UpdateExpression using ADD from zero (#2975)
When using the ADD syntax to sum up different components
the path that is provided is allowed to be non-existent.
In such a case DynamoDB will initialize it depending on
the type of the value.
If it is a number it will be initialized with 0.
If it is a set it will be initialized with an empty set.
2020-05-07 21:29:20 +01:00
Bert Blommers
2e737a6102 DynamoDB - Add tests to verify Atomic Counter functionality 2020-05-01 14:19:20 +01:00
Steve Pulec
30a98de687
Merge pull request #2924 from pvbouwel/ddb_full_parsing_executor
Improve DDB expressions support4: Execution using AST
2020-04-26 15:53:25 -05:00
pvbouwel
ec731ac901 Improve DDB expressions support4: Execution using AST
Part of structured approach for UpdateExpressions:
 1) Expression gets parsed into a tokenlist (tokenized)
 2) Tokenlist get transformed to expression tree (AST)
 3) The AST gets validated (full semantic correctness)
 4) AST gets processed to perform the update -> this commit

This commit uses the AST to execute the UpdateExpression.
All the existing tests pass. The only tests that have been
updated are in test_dynamodb_table_with_range_key.py because
they wrongly allow adding a set to a path that doesn't exist.
This has been alligend to correspond to the behavior of AWS
DynamoDB.

This commit will resolve https://github.com/spulec/moto/issues/2806
Multiple tests have been implemented that verify this.
2020-04-26 15:59:12 +01:00
Bert Blommers
56aa454397 Merge branch 'master' into feature/dynamodb_transact_write_items 2020-04-26 10:24:27 +01:00
Steve Pulec
8595493aee
Merge branch 'master' into feature/dynamodb_item_limit 2020-04-25 18:38:08 -05:00
Steve Pulec
dbeb16d9b9
Merge pull request #2823 from bblommers/bug/2797
DynamoDB - Allow case insensitive AND in KeyConditionExpression
2020-04-25 18:35:51 -05:00
Dmitry Ryzhikov
e866df9b9d Merge branch 'master' into fix/table-filter-value-error 2020-04-22 20:08:05 +03:00
Dmitry Ryzhikov
1a3a7d6a92 Add test for missing table name 2020-04-20 20:23:37 +03:00
pvbouwel
e6b51a28ee Enable AST Validation
This commit puts AST validation on the execution path. This means updates get
validated prior to being executed. There were quite a few tests that were not
working against Amazon DDB. These tests I considered broken and as such this
commit adapts them such that they pass against Amazon DDB.

test_update_item_on_map()
=> One of the SET actions would try to set a nested element by specifying the nesting on the path
   rather than by putting a map as a value for a non-existent key. This got changed.

test_item_size_is_under_400KB
=> Used the keyword "item" which DDB doesn't like. Change to cont in order to keep the same sizings.
=> Secondly the size error messages differs a bit depending whether it is part of the update or part
   of a put_item. For an update it should be:
   Item size to update has exceeded the maximum allowed size
   otherwise it is
   Item size has exceeded the maximum allowed size'

test_remove_top_level_attribute
=> Used a keyword item.  Use ExpressionAttributeNames

test_update_item_double_nested_remove
=> Used keywords name & first. Migrated to non-deprecated API and use ExpressionAttributeNames

test_update_item_set &
test_boto3_update_item_conditions_pass &
test_boto3_update_item_conditions_pass_because_expect_not_exists &
test_boto3_update_item_conditions_pass_because_expect_not_exists_by_compare_to_null &
test_boto3_update_item_conditions_pass_because_expect_exists_by_compare_to_not_null &
test_boto3_update_item_conditions_fail &
test_boto3_update_item_conditions_fail_because_expect_not_exists &
test_boto3_update_item_conditions_fail_because_expect_not_exists_by_compare_to_null
=> Were broken tests which had string literal instead of value placeholder
2020-04-19 16:58:46 +01:00
pvbouwel
fc4d88401d Improve DDB expressions support3: AST Validation
Part of structured approach for UpdateExpressions:
 1) Expression gets parsed into a tokenlist (tokenized)
 2) Tokenlist get transformed to expression tree (AST)
 3) The AST gets validated (full semantic correctness) -> this commit
 4) AST gets processed to perform the update

This commit uses the AST to perform validation.  Validation makes sure the
nodes encounterd have valid values and they will also resolve values for
references that refer to item state or values passed into the expression.
2020-04-19 16:58:07 +01:00
pvbouwel
9ed613e197 Better DDB expressions support2: ExpressionTree
Part of structured approach for UpdateExpressions:
 1) Expression gets parsed into a tokenlist (tokenized)
 2) Tokenlist get transformed to expression tree (AST) -> This commit
 3) The AST gets validated (full semantic correctness)
 4) AST gets processed to perform the update

This commit uses the tokenlist to build an expression tree. This tree is not
yet used. Still it allows to raise additional Validation Exceptions which
previously were missed silently therefore it allows tests to catch these type of
ValidationException. For that reason DDB UpdateExpressions will be parsed
already. It also makes sure we won't break existing tests.

One of the existing tests had to be changed in order to still pass:
 - test_dynamodb_table_with_range_key.test_update_item_with_expression

This test passed in a numeric literal which is not supported by DynamoDB
and with the current tokenization it would get the same error as in AWS
DynamoDB.
2020-04-18 09:19:03 +01:00
pvbouwel
7ea419dd54 Better DDB expressions support1: TokenizationDDB
Currently the mock for DynamoDB has adhoc code to implement
its updateExpression functionality.  This series will
transform the logic such that Update Expressions are processed
as follows:
 1) Expression gets parsed into a tokenlist (tokenized) -> This commit
 2) Tokenlist get transformed to expression tree (AST)
 3) The AST gets validated (full semantic correctness)
 4) AST gets processed to perform the update

This alows for a more realistic mocking. It will throw exceptions much
more aggressively avoiding situations where a test passes against the
mock but fails with an exception when running against AWS.

Introduction of step 3 also allows to have the update expression as an
atomic unit of work. So updates at the start of the expression cannot
be performed if there is an error further down the expression.

This specific commit will tokenize expressions but the tokenlist is not
yet used. It is purely to keep clear boundaries.  It does do a minor
refactoring of the exceptions to allow more re-use and to ease testing.

This series of changes is to aid providing a long-term solution for
https://github.com/spulec/moto/issues/2806.
2020-04-18 09:16:23 +01:00
Bert Blommers
870b34ba76 Spacing 2020-04-16 07:09:50 +01:00
Bert Blommers
47d80621f9 Merge branch 'master' into feature/dynamodb_item_limit 2020-04-16 07:07:59 +01:00
Bert Blommers
a6902e8713
Update tests/test_dynamodb2/test_dynamodb.py
Co-Authored-By: Guilherme Martins Crocetti <gmcrocetti@gmail.com>
2020-04-15 07:26:09 +01:00
Bert Blommers
c2b4c397f2 DDB test - Fix KeySchema, and set BillingMode for easier online testing 2020-04-14 07:53:15 +01:00
Bert Blommers
54f51fc7c1 DynamoDB - TransactWriteItems implementation 2020-04-08 10:49:58 +01:00