[#1635]Add model name in DoesNotExist and MultipleObjectsReturned message #1637
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.
Description
Add the model.name field to the DoesNotExist and MultipleObjectsReturned exception message to obtain clearer prompts when calling the model. get() method.
Motivation and Context
When I use the Model.get() method and a DoesNotExist exception occurs because there is no corresponding record in the database, the provided error message is often not specific enough for me to quickly identify which Model is involved. The message "Object does not exist" is too generic.
#1635
How Has This Been Tested?
I executed the
make test
command and passed all tests related to the get() method, such as thetest_get
method intest_queryset.py
.testing environment: python: 3.10.6
There's something I need to say. I checked the code about DoesNotExist and MultipleObjectsReturned, and noticed that in the _getbypk method of models.py, DoesNotExist was processed and returned cls._meta.full_name, Is this a place that needs to be modified synchronously?
Checklist: