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 updating set to empty #1189

Merged
merged 3 commits into from
Jul 18, 2023
Merged

Fix updating set to empty #1189

merged 3 commits into from
Jul 18, 2023

Conversation

ikonst
Copy link
Contributor

@ikonst ikonst commented Jul 12, 2023

Fixes #962.

Empty sets are not supported by DynamoDB. Currently we're representing empty sets by unsetting the attribute (hence it's indistinguishable from unsetting), i.e.

m1.my_set = set()
m1.save()
m2.my_set = None
m2.save()

then

m1.refresh()
m2.refresh()
assert m1.my_set == m2.my_set == None

Another way to empty the set should be through an update expression:

m1.update([MyModel.my_set.set([]))

We're not changing this semantic here, but we're making it so that m1.update([MyModel.my_set.set([])) doesn't crash in botocore.

When preparing an update expression, we've been sending update expressions like {':0': {'NS': None}} which crashed botocore with "TypeError: 'NoneType' object is not iterable". The PR addresses it by using a REMOVE action when assigning an empty value to a set.

@ikonst ikonst force-pushed the 07-11-update-set-to-empty branch from f40bb99 to b13dc6e Compare July 12, 2023 04:56
@ikonst
Copy link
Contributor Author

ikonst commented Jul 13, 2023

@jmphilli are you still dynamo-ing?

@anandswaminathan
Copy link
Contributor

@ikonst Reviewing

@@ -298,9 +298,12 @@ def __getitem__(self, item: Union[int, str]) -> 'Path':
def __or__(self, other):
return _IfNotExists(self, self._to_operand(other))

def set(self, value: Any) -> SetAction:
def set(self, value: Any) -> Union[SetAction, RemoveAction]:
# Returns an update action that sets this attribute to the given value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: "Sets/removes" attribute

@ikonst ikonst merged commit 335c7cd into master Jul 18, 2023
10 checks passed
@ikonst ikonst deleted the 07-11-update-set-to-empty branch July 18, 2023 05:37
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

Successfully merging this pull request may close these issues.

Setting <UnicodeSetAttribute>.set([]) (empty list) throws "Nonetype is not iterable" error.
2 participants