dynobase-icon
Dynobase

Error: dynamodb query is not null

Rafal Wilinski

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.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.