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

Empty-set safety #145

Open
ojii opened this issue Nov 28, 2022 · 3 comments
Open

Empty-set safety #145

ojii opened this issue Nov 28, 2022 · 3 comments

Comments

@ojii
Copy link
Contributor

ojii commented Nov 28, 2022

aiodynamo used to be empty-string-safe when DynamoDB didn't support empty string values. This mercifully got fixed in DynamoDB, but DynamoDB still doesn't accept empty sets (NS, SS, BS). There's an argument to be made that aiodynamo should handle this automatically, converting F("some_set").set(set()) to F("some_set").remove(), possibly with a warning.

@dimaqq
Copy link
Contributor

dimaqq commented Nov 28, 2022

Is that what amazing dunamo db does? Let's say if there's an item with a set with 1 element and later that element is removed.

@ojii
Copy link
Contributor Author

ojii commented Nov 28, 2022

Is that what amazing dunamo db does? Let's say if there's an item with a set with 1 element and later that element is removed.

this test fails for the .set(...) case, but succeeds for the .delete(...) case. Meaning, DynamoDB is seemingly okay with empty sets so long as they have previously had values in them, just not creating new ones. Absolutely baffling.

@pytest.mark.parametrize("op", [F("set").set(set()), F("set").delete({"a"})])
async def test_empty_set(client: Client, table: TableName, op):
    await client.put_item(table, {"h": "h", "r": "r", "set": {"a"}})
    await client.update_item(table, {"h": "h", "r": "r"}, op)

EDIT: Actually, F("set").delete({"a"}) causes the key to be removed from the item 😱

@ojii
Copy link
Contributor Author

ojii commented Nov 29, 2022

🤔 this gets even more complicated because of F.set_if_not_exists which doesn't have an equivalent for empty sets from what I can see (eg "remove_if_not_exists")

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

2 participants