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

Use attr.get_value(value) when deserialize #450

Conversation

betamoo
Copy link
Contributor

@betamoo betamoo commented Feb 27, 2018

Change update & update_item to use attr.get_value(value) in deserialization.

The PR #149 introduced attr.get_value(value) for backward compatibility between LBA and BA, and used it in model.from_raw_data but not in model.update_item (nor model.update) causing code like https://gist.github.com/betamoo/1fb15692d6fa74b9ddacfd4965632b26 to fail

@jeremypian
Copy link

can you add some tests?

assert True == LBAModel.get('pkey1').flag
assert False == LBAModel.get('pkey2').flag
assert None == LBAModel.get('pkey3').flag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the change, update_item will throw TypeError: expected string or buffer

assert True == LBAModel.get('pkey1').flag
assert False == LBAModel.get('pkey2').flag
assert None == LBAModel.get('pkey3').flag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the change, update will throw TypeError: expected string or buffer



@pytest.mark.ddblocal
def test_legacy_boolean_attribute_deserialization_compatibility(ddb_url):

Choose a reason for hiding this comment

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

you can probably pytest.mark.parametrize those two tests

@jeremypian
Copy link

+1

assert None == BAModel.get('pkey3').flag

# Update a value in the model causing BooleanAttribute to be deserialized
BAModel.get('pkey1').update(actions=[BAModel.value.set('value2')])

Choose a reason for hiding this comment

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

would it make sense to perform this set of updates on top of fresh LBAModel saves, instead of after update_item calls? technically update_item could correct the issue for the item, and the update calls would succeed even without the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes sense

Copy link

@harleyk harleyk left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@harleyk harleyk merged commit 8ab34d0 into pynamodb:master Mar 1, 2018
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.

None yet

5 participants