Commit Graph

280 Commits

Author SHA1 Message Date
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
Andrea Amorosi
349b381390 Fixed dynamodb2 put_item ValidationException 2020-03-28 17:59:42 +00:00
Bert Blommers
e82e1e3f39 DynamoDB - Add 1MB item size check 2020-03-21 12:20:09 +00:00
Bert Blommers
b1da99aeda #2797 - DynamoDB - Allow case insensitive AND in KeyConditionExpression 2020-03-20 12:29:04 +00:00
Steve Pulec
14b2811157
Merge pull request #2819 from bblommers/dynamodb_global_index_ordering
Dynamodb - Global index ordering
2020-03-19 19:39:09 -05:00
Steve Pulec
78f5541953
Merge pull request #2817 from bblommers/dynamodb_add_index_status
DynamoDB - Add status to Global Indexes
2020-03-19 19:37:49 -05:00
Bert Blommers
71bf314a0f
Merge pull request #2799 from ImFlog/fix_dynamodb_updated_new
Fix UPDATED_NEW return values differences
2020-03-18 08:21:01 +00:00
Bert Blommers
aead80c392
Add missing region 2020-03-17 17:11:35 +00:00
Bert Blommers
67c7fce85e #2760 - DynamoDB - Ensure proper ordering for Numeric sort keys 2020-03-17 16:28:49 +00:00
Bert Blommers
b7da6b9481 #2813 - DynamoDB - Add Global Index Status 2020-03-17 15:41:50 +00:00
Steve Pulec
77b1cc2321
Merge pull request #2809 from bblommers/feature/dynamodb-transact-get-items
Feature - DynamoDB: transact_get_items
2020-03-15 16:45:03 -05:00
ImFlog
7f6c6660aa Add some new update_new tests 2020-03-13 09:37:50 +01:00
Bert Blommers
71d3941daf Linting 2020-03-12 14:26:23 +00:00
Bert Blommers
caebe222d7 DynamoDB - Transact_get_items - Remove error condition 2020-03-12 14:24:53 +00:00
Tomoya Iwata
b74625db0c add support for dynamodb transact_get_items 2020-03-12 14:15:13 +00:00
ImFlog
ba1bf09474 Fix UPDATED_NEW return values differences between moto and dynamoDB 2020-03-10 18:22:54 +01:00
Bert Blommers
315ac32f09
Add region to test case 2020-03-10 14:28:12 +00:00
Bert Blommers
6ba00d9ad1 #1054 - DynamoDB - Improve error handling for put_item without keys 2020-03-10 13:25:40 +00:00
heyder.dias
f5080e539d fix lint check 2020-03-05 18:39:20 -03:00
heyder.dias
fa7f83bc2f add test to nested if_not_exists and property already exists 2020-03-05 17:05:00 -03:00
Bert Blommers
2bd93a76fc Add region to DDB tests 2020-02-09 11:58:41 +00:00
Bert Blommers
936d686392 #2580 - DynamoDB update_item: Allow list_append and if_not_exists-functions in one expression 2020-02-09 11:47:02 +00:00
Nikita Antonenkov
d4caf14b61 Fixed UnboundLocalError in dynamodb2.query when no filters are passed 2020-02-07 23:39:31 +01:00
Steve Pulec
663d7c289b
Merge pull request #2675 from bblommers/bugfix/#2674
DynamoDB - ListAppend should also work when adding maps to a list
2020-01-22 20:01:53 -06:00
Bert Blommers
7ff7ee4e8e Test fix - Region must be specified 2020-01-22 11:42:06 +00:00
Bert Blommers
6f02782624 #2627 - Change comparison to differentiate between 0 and None 2020-01-22 11:30:17 +00:00
Bert Blommers
8c920cce10 Specify region in tests 2020-01-12 12:20:55 +00:00
Bert Blommers
9ce1ee49d7 #2626 - DynamoDB - FilterExpression should ignore items with non-existent attribute 2020-01-12 12:05:08 +00:00
Bert Blommers
5f59cb7fb0 #2674 - ListAppend should also work when adding maps to a list 2020-01-06 08:16:09 +00:00
Asher Foa
7d4c15d53e skip part of the test in server mode. 2019-12-24 11:01:54 -08:00
Asher Foa
299e7851d6 Add assertions. 2019-12-24 10:23:46 -08:00
Asher Foa
5bd3827b26 run black 2019-12-20 18:55:58 -08:00
Asher Foa
a6f14eee3f Add test to repo stream issue 2019-12-20 18:55:58 -08:00
Ilya Shmygol
704a12146b Improve error reporting for missing index 2019-12-12 10:49:07 +01:00
Ilya Shmygol
3a42079ec7 Merge remote master 2019-12-11 16:17:21 +01:00
Ilya Shmygol
be5986c0b5 Test query by non exists index 2019-12-11 15:08:45 +01:00
Mike Grima
4d5bf1c5c6
Merge pull request #2605 from bblommers/dynamodb_add_nested_stringsets
Dynamodb - DELETE/ADD item from/to nested sets
2019-12-09 14:14:56 -08:00
Bert Blommers
e41bc9fc58 DynamoDB - DELETE item from nested sets 2019-11-28 13:22:20 +00:00
Bert Blommers
6d7ad717df DynamoDB - ADD item to nested sets 2019-11-27 12:36:42 +00:00
Bert Blommers
21a1d4d604 DynamoDB - list_append operation can be made in a nested map 2019-11-25 15:19:22 +00:00
Steve Pulec
72da9e96c2 Lint. 2019-11-21 17:53:58 -05:00
Mike Grima
bd777cad44 Fix for moto not unmocking.
- Fixes #2575
- Also upgraded Travis CI to make use of Bionic instead of Xenial
- This may also address concerns raised in #1793
2019-11-18 15:28:31 -08:00
Bert Blommers
993819bd41 #2562 - DynamoDB - allow updates to be of a different type 2019-11-15 15:54:21 +00:00
Bert Blommers
eaa23800bd Linting 2019-11-03 07:33:27 -08:00
Bert Blommers
5876dc0186 Fix test - List order does not matter for projectionexpression 2019-11-03 07:14:19 -08:00
Bert Blommers
6a601d7d5c #2527 - DynamoDB - Allow nested attributes in ProjectionExpressions 2019-11-03 14:09:27 +00:00
Asher Foa
96e5b1993d Run black on moto & test directories. 2019-10-31 10:36:05 -07:00
Bert Blommers
997177e43e #847 - Fix tests to be compatible with python3 2019-10-23 02:26:26 -07:00
Bert Blommers
730c4be1a3 #847 - DynamoDB - Implement list_append feature when updating 2019-10-23 09:12:03 +01:00
Bert Blommers
64cf1fc2c9 Refactor DynamoDB update expressions (#2497)
* Refactor DynamoDB.update to use recursive method for nested updates

* Simplify DynamoDB.update_item logic
2019-10-22 12:40:41 -07:00
Bert Blommers
db206e994b #250 - DynamoDB - Add check for valid query keyconditionexpression 2019-10-18 09:58:09 +01:00
Bert Blommers
009a97db85 Merge branch 'master' into bugfix/1823 2019-10-14 10:02:22 +01:00
Bert Blommers
106692ed88 #1823 - Add support to delete items from a nested list 2019-10-14 09:59:52 +01:00
Mike Grima
893f0d4f83
Merge pull request #2463 from gruebel/fix-dynamodb-get-item-ProjectionExpression
Add ProjectionExpression & ExpressionAttributeNames to DynamoDB get_it…
2019-10-13 10:47:25 -07:00
gruebel
97c4174f30 Extract projection_expression adjustment 2019-10-11 14:30:25 +02:00
Steve Pulec
34d4379b9f
Merge branch 'master' into bugfix/2384 2019-10-10 17:02:59 -05:00
Bert Blommers
cf899eecff #2384 - Add test case 2019-10-10 09:33:11 +01:00
Bert Blommers
afb8f71e9f #1822 - DynamoDB: Add List index operations 2019-10-09 17:30:42 +01:00
Bert Blommers
e759b565da #1874 - Change tests to use resource/client when appropriate 2019-10-09 10:02:40 +01:00
Bert Blommers
1fb844972f Merge branch 'master' into bugfix/1874 2019-10-09 08:33:53 +01:00
gruebel
cb43796daf Add ProjectionExpression & ExpressionAttributeNames o DynamoDB get_item & batch_get_item 2019-10-08 22:30:14 +02:00
Bert Blommers
c9348bc45c #1874 - Add tests for more complex items 2019-10-08 15:51:46 +01:00
gruebel
c9d69681ec Add evaluation of ConditionExpression to DynamoDB2 delete_item 2019-10-06 16:49:02 +02:00