Skip to content
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 Query Filter Expression Doesn't Work #1229

Closed
1 task
hxk1633 opened this issue Dec 30, 2024 · 1 comment
Closed
1 task

DynamoDB Query Filter Expression Doesn't Work #1229

hxk1633 opened this issue Dec 30, 2024 · 1 comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@hxk1633
Copy link

hxk1633 commented Dec 30, 2024

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

@hxk1633 hxk1633 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 30, 2024
@hxk1633 hxk1633 closed this as completed Dec 30, 2024
Copy link

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant