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

🧹 Fix the if statement that prevents using conditions on Partition Keys #6037

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/test_dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,18 @@ def test_may_not_use_condition_on_index_partition_key(self):
'id': dynamo.BeginsWith('k'),
})

def test_may_not_use_condition_on_table_with_only_partition_key(self):
self.table = dynamo.Table(
dynamo.MemoryStorage(),
'table',
partition_key='id',
)

with self.assertRaises(ValueError):
self.table.get_many({
'id': dynamo.BeginsWith('k'),
})

def test_can_disambiguate_between_indexes_with_same_pk(self):
self.table = dynamo.Table(
dynamo.MemoryStorage(),
Expand Down
4 changes: 3 additions & 1 deletion website/dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,9 @@ def decode_object(obj):
def validate_only_sort_key(conds, sort_key):
"""Check that non-Equals conditions are only used on the sort key."""
non_equals_fields = [k for k, v in conds.items() if not isinstance(v, Equals)]
if sort_key and set(non_equals_fields) - {sort_key}:
sort_key_set = {sort_key} if sort_key else set()

if set(non_equals_fields) - sort_key_set:
raise ValueError(f"Non-Equals conditions only allowed on sort key {sort_key}, got: {list(conds)}")


Expand Down
Loading