You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The check in to_dict uses if not self.exists: which references the method object, not its return value. This will always evaluate to False and never return None. It should likely be if not self.exists():.
Call the exists method instead of referencing it to ensure the check is executed. As written, the condition always evaluates to False, never returning None for non-existent documents.
def to_dict(self) -> Document:
- if not self.exists:+ if not self.exists():
return None
return self._doc
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies that exists is a method and must be called (exists()); otherwise the condition is always truthy, breaking the new behavior to return None for non-existent docs. This is a correctness bug fix with high impact.
High
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
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.
PR Type
Bug fix, Tests
Description
Return None for non-existent documents
Adjust tests to expect None
Align mock behavior with Firestore
Diagram Walkthrough
File Walkthrough
document.py
to_dict returns None for missing documentsmockfirestore/document.py
test_document_reference.py
Update test to reflect None returntests/test_document_reference.py