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

get() with a non-existent value as the primary key using where returns a collection with null instead of an empty collection #278

Open
crhg opened this issue Feb 7, 2024 · 0 comments

Comments

@crhg
Copy link
Contributor

crhg commented Feb 7, 2024

Describe the bug

Assume the name of the primary key in table foos is id.

Foo::where('id', '__non_existent__')->get()

Expected result:
Empty collection

> Foo::where('id', '__non_existent__')->get()
= BaoPham\DynamoDb\DynamoDbCollection {#8448
    all: [],
  }

Actual result:
Collection with null as an element.

> Foo::where('id', '__non_existent__')->get()
= BaoPham\DynamoDb\DynamoDbCollection {#8126
    all: [
      null,
    ],
  }

\BaoPhamDynamoDbQueryBuilder::getAll performs the following special logic when exact search is available. If item does not exist and null is returned, it should return an empty collection.

        if ($analyzer->isExactSearch()) {
            $item = $this->find($analyzer->identifierConditionValues(), $columns);

            return $this->getModel()->newCollection([$item]);
        }

Schema

Describe your table schema:

  • Primary key / composite key
    AttributeName: id
    AttributeType: S
    KeyType: HASH

  • Any index?
    no

Debug info

> Foo::where('id', '__non_existent__')->toDynamoDbQuery()
= BaoPham\DynamoDb\RawDynamoDbQuery {#7193
    +op: "Query",
    +query: [
      "TableName" => "foos",
      "KeyConditionExpression" => "#id = :a1",
      "ExpressionAttributeNames" => [
        "#id" => "id",
      ],
      "ExpressionAttributeValues" => [
        ":a1" => [
          "S" => "__non_existent__",
        ],
      ],
    ],
  }

Version info

  • Laravel: 10.43.0
  • laravel-dynamodb: 6.4.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant