Fix get method in models.py to not throw an exception when returning an empty item.#1289
Open
domderen wants to merge 3 commits intopynamodb:masterfrom
Open
Fix get method in models.py to not throw an exception when returning an empty item.#1289domderen wants to merge 3 commits intopynamodb:masterfrom
domderen wants to merge 3 commits intopynamodb:masterfrom
Conversation
…an empty item. Fix for issue pynamodb#1287 (comment) When getting a model value with `attributes_to_get` parameter, set in a way where it could return an empty object, the get method is erronously throwing an exception even though the object exists. This fixes the issue.
ikonst
reviewed
Sep 16, 2025
pynamodb/models.py
Outdated
| item_data = data.get(ITEM) | ||
| if item_data: | ||
| return cls.from_raw_data(item_data) | ||
| if ITEM in data: |
Contributor
There was a problem hiding this comment.
probably if data and ITEM in data:
Contributor
|
Are you going to add a test? |
Author
|
Hey, let me know whatt you think :) |
ikonst
reviewed
Sep 16, 2025
ikonst
reviewed
Sep 16, 2025
ikonst
reviewed
Sep 16, 2025
ikonst
reviewed
Sep 16, 2025
ikonst
reviewed
Sep 16, 2025
ikonst
reviewed
Sep 16, 2025
Author
|
Hey, I updated the comments, and I removed the second test as indeed there were other places that already check if this exception is thrown when In regards to better asserts, I'm now checking if the property we are trying to get indeed does not exist, even though the object is of correct type. Is this something more in line with your thinking? |
Author
|
Hey, any update on that? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for issue #1287 (comment) When getting a model value with
attributes_to_getparameter, set in a way where it could return an empty object, the get method is erronously throwing an exception even though the object exists. This fixes the issue.