Skip to content

DynamoDB Query Filter Expression Doesn't Work #1229

@hxk1633

Description

@hxk1633

Describe the bug

The filter_expression method for a dynamodb query does nothing. I try the same filter expression in the AWS DynamoDB console and it works as expected. I'm not sure how to debug this issue on my end.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I expect my query filter expression to return results.

Current Behavior

The query filter expression returns an empty result with no errors.

Reproduction Steps

This is the full code of the query to reproduce the issue.

      let gsi2_pk = format!("STATUSES ACCOUNT#{}", &account_id.to_string());
      let mut req = self
          .client
          .query()
          .table_name(&self.table_name)
          .index_name("StatusHistoryByAccount")
          .scan_index_forward(false)
          .key_condition_expression("GSI2PK = :account_id")
          .expression_attribute_values(":account_id", AttributeValue::S(gsi2_pk))
          .limit(limit);

      if let Some(next) = next {
          req = req.set_exclusive_start_key(Some(next.into()));
      }

      if let Some(sort) = sort {
          match sort.sort_by.as_str() {
              "createdAt" => {
                  req = match sort.sort_order.as_str() {
                      "asc" => req.scan_index_forward(true),
                      "desc" => req.scan_index_forward(false),
                      _ => req,
                  }
              }
              _ => (),
          }
      }

      if let Some(day) = &filters.day {
          req = req.filter_expression("DayKey = :day");
          req = req.expression_attribute_values(":day", AttributeValue::S(day.to_owned()));
      }   
  
      let res = req.send().await?;

      let statuses = match res.items {
          Some(items) => items
              .into_iter()
              .map(|item| item.try_into())
              .collect::<Result<Vec<DeviceStatus>, _>>()?,
          None => Vec::default(),
      };
      let next = res.last_evaluated_key.map(|m| m.into());
      Ok(DeviceStatusRange { statuses, next })
  }

Possible Solution

No response

Additional Information/Context

No response

Version

├── aws-config v1.0.1
│   ├── aws-credential-types v1.0.1
│   │   ├── aws-smithy-async v1.0.2
│   │   ├── aws-smithy-runtime-api v1.0.2
│   │   │   ├── aws-smithy-async v1.0.2 (*)
│   │   │   ├── aws-smithy-types v1.0.2
│   │   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-http v0.60.0
│   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-types v1.0.1
│   │   │   ├── aws-credential-types v1.0.1 (*)
│   │   │   ├── aws-smithy-async v1.0.2 (*)
│   │   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   │   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-runtime v1.0.1
│   │   ├── aws-credential-types v1.0.1 (*)
│   │   ├── aws-http v0.60.0 (*)
│   │   ├── aws-sigv4 v1.0.1
│   │   │   ├── aws-credential-types v1.0.1 (*)
│   │   │   ├── aws-smithy-http v0.60.0
│   │   │   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   │   │   ├── aws-smithy-types v1.0.2 (*)
│   │   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-smithy-async v1.0.2 (*)
│   │   ├── aws-smithy-http v0.60.0 (*)
│   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-types v1.0.1 (*)
│   ├── aws-sdk-sso v1.3.0
│   │   ├── aws-credential-types v1.0.1 (*)
│   │   ├── aws-http v0.60.0 (*)
│   │   ├── aws-runtime v1.0.1 (*)
│   │   ├── aws-smithy-async v1.0.2 (*)
│   │   ├── aws-smithy-http v0.60.0 (*)
│   │   ├── aws-smithy-json v0.60.0
│   │   │   └── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-smithy-runtime v1.0.2
│   │   │   ├── aws-smithy-async v1.0.2 (*)
│   │   │   ├── aws-smithy-http v0.60.0 (*)
│   │   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-types v1.0.1 (*)
│   ├── aws-sdk-ssooidc v1.3.0
│   │   ├── aws-credential-types v1.0.1 (*)
│   │   ├── aws-http v0.60.0 (*)
│   │   ├── aws-runtime v1.0.1 (*)
│   │   ├── aws-smithy-async v1.0.2 (*)
│   │   ├── aws-smithy-http v0.60.0 (*)
│   │   ├── aws-smithy-json v0.60.0 (*)
│   │   ├── aws-smithy-runtime v1.0.2 (*)
│   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-types v1.0.1 (*)
│   ├── aws-sdk-sts v1.3.1
│   │   ├── aws-credential-types v1.0.1 (*)
│   │   ├── aws-http v0.60.0 (*)
│   │   ├── aws-runtime v1.0.1 (*)
│   │   ├── aws-smithy-async v1.0.2 (*)
│   │   ├── aws-smithy-http v0.60.0 (*)
│   │   ├── aws-smithy-json v0.60.0 (*)
│   │   ├── aws-smithy-query v0.60.0
│   │   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-smithy-runtime v1.0.2 (*)
│   │   ├── aws-smithy-runtime-api v1.0.2 (*)
│   │   ├── aws-smithy-types v1.0.2 (*)
│   │   ├── aws-smithy-xml v0.60.0
│   │   ├── aws-types v1.0.1 (*)
│   ├── aws-smithy-async v1.0.2 (*)
│   ├── aws-smithy-http v0.60.0 (*)
│   ├── aws-smithy-json v0.60.0 (*)
│   ├── aws-smithy-runtime v1.0.2 (*)
│   ├── aws-smithy-runtime-api v1.0.2 (*)
│   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-types v1.0.1 (*)
├── aws-sdk-dynamodb v1.3.0
│   ├── aws-credential-types v1.0.1 (*)
│   ├── aws-http v0.60.0 (*)
│   ├── aws-runtime v1.0.1 (*)
│   ├── aws-smithy-async v1.0.2 (*)
│   ├── aws-smithy-http v0.60.0 (*)
│   ├── aws-smithy-json v0.60.0 (*)
│   ├── aws-smithy-runtime v1.0.2 (*)
│   ├── aws-smithy-runtime-api v1.0.2 (*)
│   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-types v1.0.1 (*)
├── aws-sdk-iotdataplane v1.3.0
│   ├── aws-credential-types v1.0.1 (*)
│   ├── aws-http v0.60.0 (*)
│   ├── aws-runtime v1.0.1 (*)
│   ├── aws-smithy-async v1.0.2 (*)
│   ├── aws-smithy-http v0.60.0 (*)
│   ├── aws-smithy-json v0.60.0 (*)
│   ├── aws-smithy-runtime v1.0.2 (*)
│   ├── aws-smithy-runtime-api v1.0.2 (*)
│   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-types v1.0.1 (*)
├── aws-sdk-secretsmanager v1.3.0
│   ├── aws-credential-types v1.0.1 (*)
│   ├── aws-http v0.60.0 (*)
│   ├── aws-runtime v1.0.1 (*)
│   ├── aws-smithy-async v1.0.2 (*)
│   ├── aws-smithy-http v0.60.0 (*)
│   ├── aws-smithy-json v0.60.0 (*)
│   ├── aws-smithy-runtime v1.0.2 (*)
│   ├── aws-smithy-runtime-api v1.0.2 (*)
│   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-types v1.0.1 (*)
├── aws-sdk-sqs v1.3.0
│   ├── aws-credential-types v1.0.1 (*)
│   ├── aws-http v0.60.0 (*)
│   ├── aws-runtime v1.0.1 (*)
│   ├── aws-smithy-async v1.0.2 (*)
│   ├── aws-smithy-http v0.60.0 (*)
│   ├── aws-smithy-json v0.60.0 (*)
│   ├── aws-smithy-runtime v1.0.2 (*)
│   ├── aws-smithy-runtime-api v1.0.2 (*)
│   ├── aws-smithy-types v1.0.2 (*)
│   ├── aws-types v1.0.1 (*)

Environment details (OS name and version, etc.)

Ubuntu 22.04.4 LTS

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions