-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Doc'd Model.MultipleObjectsReturned docs and improved documentation related with models exceptions. #13194
Doc'd Model.MultipleObjectsReturned docs and improved documentation related with models exceptions. #13194
Conversation
4616bb8
to
4063905
Compare
4063905
to
975080a
Compare
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.
Already reading much more clearly, thanks.
975080a
to
3d88663
Compare
Thank you very much for all your review today 🤘 |
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.
@adamchainz Thanks 👍 I moved DoesNotExist
to a separate commit and pushed small edits.
docs/ref/models/fields.txt
Outdated
|
||
>>> user.supervisor_of | ||
Traceback (most recent call last): | ||
... | ||
DoesNotExist: User matching query does not exist. | ||
RelatedObjectDoesNotExist: User matching query does not exist. |
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.
RelatedObjectDoesNotExist: User matching query does not exist. | |
RelatedObjectDoesNotExist: User has no supervisor_of. |
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.
Yes it's good to show the right error message 😅
docs/ref/models/querysets.txt
Outdated
@@ -1844,34 +1844,42 @@ they query the database each time they're called. | |||
.. method:: get(**kwargs) | |||
|
|||
Returns the object matching the given lookup parameters, which should be in | |||
the format described in `Field lookups`_. | |||
the format described in `Field lookups`_. Normally you should use lookups |
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 chopped Normally
.
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 think there are use cases where the database doesn't have any uniqueness constraints but application level logic is relied on for unique results with given lookups. This even aplpies when using order_with_respect_to
.
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.
Maybe we will chop also "... by the database". This should cover all cases.
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.
That sounds reasonable and shorter. I've pushed the change.
docs/ref/models/querysets.txt
Outdated
e = Entry.objects.get(id=3) | ||
b = Blog.objects.get(id=1) | ||
blog = Blog.objects.get(id=1) | ||
entry = Entry.objects.get(blog=blog, id=3) |
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.
entry = Entry.objects.get(blog=blog, id=3) | |
entry = Entry.objects.get(blog=blog, entry_number=1) |
abdfb7d
to
ded6354
Compare
ded6354
to
df62816
Compare
Changes LGTM |
…elated with models exceptions.
df62816
to
bc4fea9
Compare
DoesNotExist and MultipleObjectsReturned are very similar but had very different documentation prior to this change. I also added a note that get() should generally be used for lookups that the DB guarantees uniqueness on.