This repository was archived by the owner on Dec 1, 2025. It is now read-only.
forked from MongoEngine/mongoengine
-
Notifications
You must be signed in to change notification settings - Fork 8
Meaningful reference errors #28
Open
thomasst
wants to merge
1
commit into
master
Choose a base branch
from
meaningful-reference-errors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,19 @@ def __delslice__(self, i, j): | |
|
|
||
|
|
||
| class DocumentProxy(LocalProxy): | ||
| __slots__ = ('__document_type', '__document', '__pk') | ||
| __slots__ = ( | ||
| '__document_type', | ||
| '__document', | ||
| '__pk', | ||
| '__parent_ref_instance', | ||
| '__parent_ref_field_name', | ||
| ) | ||
|
|
||
| def _set_parent_ref(self, instance, field_name): | ||
| object.__setattr__(self, '_DocumentProxy__parent_ref_instance', | ||
| instance) | ||
| object.__setattr__(self, '_DocumentProxy__parent_ref_field_name', | ||
| field_name) | ||
|
|
||
| def __init__(self, document_type, pk): | ||
| object.__setattr__(self, '_DocumentProxy__document_type', document_type) | ||
|
|
@@ -186,7 +198,17 @@ def _get_current_object(self): | |
| collection = self.__document_type._get_collection() | ||
| son = collection.find_one({'_id': self.__pk}) | ||
| if son is None: | ||
| raise DoesNotExist('Document has been deleted.') | ||
| error = 'Document ({} {}'.format( | ||
| collection.name, self.__pk | ||
| ) | ||
| if self.__parent_ref_instance: | ||
| error += ', referenced by {} {} in field {}'.format( | ||
| self.__parent_ref_instance.__class__.__name__, | ||
| self.__parent_ref_instance.pk, | ||
| self.__parent_ref_field_name, | ||
| ) | ||
| error += ') has been deleted.' | ||
| raise DoesNotExist(error) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add the extra data as exception attributes? At some point we would want to inspect the parent object and parsing error message is not a good idea.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do this, we should start with doing it in the upstream version so that we have a consistent interface. A more informative message on the same exception is good. Raising what would essentially amount to a different exception is not good. |
||
| document = self.__document_type._from_son(son) | ||
| object.__setattr__(self, '_DocumentProxy__document', document) | ||
| return self.__document | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to avoid holding onto the parent instance as this might cause memory leaks. Store just the class (name or reference), and the instance pk.