What happens if Model.objects.get() matches more than one row?
A
It silently returns None instead
B
It raises MultipleObjectsReturned
Correct answer
C
It returns a list of all the rows
D
It returns the first matching row
Correct answer
B. It raises MultipleObjectsReturned
16 views
⚔️
Challenge a friend on Django
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
Explanation
.get() expects exactly one result: it raises DoesNotExist for zero rows and MultipleObjectsReturned for several. Use filter() when many results are possible.
Reference
Asked in: Python Developer Interviews, NTS
Doubts & discussionNot sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ What does get_object_or_404(Product, pk=5) do if no matching product exists? Next MCQ › Which Django signal can run code automatically after a model instance is saved?