Error: dynamodb query is not null

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
To query for an attribute that is not null, distinguish an absent attribute from one stored with DynamoDB’s NULL type. attribute_exists alone includes NULL values. Use an existence check plus a type check when you want present, non-null values.
import boto3
from boto3.dynamodb.conditions import Key, Attr
table = boto3.resource("dynamodb", region_name="us-east-1").Table("Orders")
page = table.query(
KeyConditionExpression=Key("pk").eq("CUSTOMER#123"),
FilterExpression=Attr("note").exists() & ~Attr("note").attribute_type("NULL"),
)
print(page.get("Items", []))The Query still needs equality on the partition key; add an optional sort-key condition when the access pattern requires it. Null tests for non-key attributes belong in FilterExpression, not KeyConditionExpression. Empty strings pass this filter because they are strings, not null.
This is one page. Continue with LastEvaluatedKey even when filtering returns no items. Filter expressions discard already-read items and do not reduce the read capacity consumed. A valid query with no matching key returns an empty result, not a query failure.
See Query usage and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB string set cannot be empty
- dynamodb throughput error
- dynamodb item size limit error
- DynamoDB Not Supported Requires @DynamoDBTyped Or @DynamoDBTypeConverted
- DynamoDB table not updating
- DynamoDB consistent read not working
- DynamoDB console unable to delete this item
- localstack dynamodb not working
- DynamoDB could not invoke null on class
- DynamoDB Query Limit Not Working
- dynamodb cannot assign requested address
- requested resource not found aws dynamodb
- AWS DynamoDB errors ResourceNotFoundException
- Float types are not supported. Use decimal types instead.
- DynamoDB type is not supported
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today