Closed SamStephens closed 4 months ago
Do the classes defined as follows fit your use-case? https://github.com/boto/boto3/blob/096e45841545f24bbd572a62504cc0dbb62e6b07/boto3/dynamodb/conditions.py#L158-L238
You can write expressions like
ConditionExpression = Or(Attr(attribute_name).not_exists(), Attr(attribute_name).lt(updated_value))
I'm not sure if they are documented anywhere
@crh23 thanks, this is exactly what I needed.
I've closing this issue as support is present, and replacing it with an issue for the missing documentation.
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.
Describe the feature
According to https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html it's possible to combine multiple conditions using
AND
andOR
. However, from my reading of https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/table/update_item.html and https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/dynamodb.html#boto3.dynamodb.conditions.Attr, it is only possible to specify a single condition using the update_item operation.Use Case
I have an attribute I want to update, but not if the update will decrease the attributes value. The attribute is not necessarily present. So I need my conditional expression to be
attribute not exists OR attribute value < my value
.It appears the API supports this conditional expression, but not this SDK.
Proposed Solution
boto3.dynamodb.conditions.Attr
, maybeboto3.dynamodb.conditions.Condition
.boto3.dynamodb.conditions.Condition
.boto3.dynamodb.conditions.Condition
three methods,And
,Or
, andNot
, that each do the obvious thing.Under this scheme, my ConditionExpression would be
Other Information
The only way I can see to workaround this is two conditional updates - firstly with
not_exists
, and then if the check fails because the attribute exists, try the update again withlt
.Acknowledgements
SDK version used
1.34.76
Environment details (OS name and version, etc.)
Ubuntu (Windows Subsystem for Linux)