Skip to content

Commit 91839de

Browse files
authored
Merge pull request #19 from RSS-Engineering/fix-complex-index-get
Fix .get() By index for dynamo
2 parents adc7e93 + 8c7c449 commit 91839de

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

pydanticrud/backends/dynamodb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def get(self, key: Union[Dict, Any]):
383383
if isinstance(key, dict):
384384
try:
385385
return self.query(
386-
Rule(" AND ".join(f"{k} == {repr(v)}" for k, v in key.items())), limit=1
386+
Rule(" and ".join(f"{k} == {repr(v)}" for k, v in key.items())), limit=1
387387
)[0]
388388
except IndexError:
389389
raise DoesNotExist(f'{self.table_name} "{key}" does not exist')

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pydanticrud"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
description = "Supercharge your Pydantic models with CRUD methods and a pluggable backend"
55
authors = ["Timothy Farrell <[email protected]>"]
66
license = "MIT"

tests/test_dynamodb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,14 @@ def test_get_simple_model_data_via_index(dynamo, simple_query_data):
540540
assert res.dict(by_alias=True) == simple_query_data[0]
541541

542542

543+
def test_get_complex_model_data_via_index(dynamo, complex_query_data):
544+
data = complex_model_data_generator()
545+
res = ComplexKeyModel.get((complex_query_data[0]['account'], complex_query_data[0]['sort_date_key']))
546+
assert res.dict(by_alias=True) == complex_query_data[0]
547+
res = ComplexKeyModel.get({"account": complex_query_data[0]['account'], "notification_id": complex_query_data[0]['notification_id']})
548+
assert res.dict(by_alias=True) == complex_query_data[0]
549+
550+
543551
def test_alias_model_validator_ingest(dynamo):
544552
data = alias_model_data_generator()
545553
AliasKeyModel(**data)

0 commit comments

Comments
 (0)