Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boto3 Dynamo DB query set FilterExpression to None?

Hi I have a couple queries I want to run on Dynamo DB, since the query FilterExpression depends on some condition I want to set it as a variable like this:

    if valid_attr:
        filter_expression = Attr('keyName').is_in(valid_attr)
    else:
        filter_expression = None

But it seems that boto3 doesn't like None values, is there some other way to do something similar? I don't want duplicated code in my script. I can't find what are the default parameters from documentation.


1 Answers

I did as following

query_parameters = {attr1: value1, attr2: value2}
if valid_attr:
    query_parameters.update({'FilterExpression': Attr('keyName').is_in(valid_attr)})
table.query(**query_parameters)
like image 155
Old Panda Avatar answered Oct 19 '25 13:10

Old Panda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!