-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DynamoDB: No way to combine multiple ConditionExpression #4112
Comments
Do the classes defined as follows fit your use-case? boto3/boto3/dynamodb/conditions.py Lines 158 to 238 in 096e458
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. |
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)
The text was updated successfully, but these errors were encountered: