MultipleObjects error when recommending review

Bug #802868 reported by Michael Nelson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ratings and Reviews server
New
Undecided
Unassigned
piston-mini-client
Invalid
Undecided
Unassigned

Bug Description

We're seeing numerous oopses each day on reviews.ubuntu.com for posts to (for example) /reviews/api/1.0/reviews/11039/recommendations/

with tracebacks like: https://pastebin.canonical.com/49101/

We lose the original trackback because a second exception is recorded while piston-miniclient tries to log the error, but there's enough info to be certain that the issue is in reviewsapp.api.handlers.SubmitUsefulnessHandler.create:
{{{
        usefulness, created = Usefulness.objects.get_or_create(
            review=review, user=request.user)
}}}
The MultipleObjectsReturned seems to imply that it is already possible (somehow) for a user to create 2 recommendations for a single review and we're erroring when they try to create a third :). Checking the model, there is currently no db constraint for this on the Usefulness model... we should add one with a migration to delete duplicates while fixing the error.

Tags: oops
description: updated
tags: added: oops
Revision history for this message
Aaron Peachey (aaronp) wrote :

The software center spec doesn't provide any reason for multiple recommendations against the same review. In fact, we built the client to keep track of usefulness submitted and hide the yes/no buttons if the user has already submitted usefulness for that review.
But it was implemented in Natty with only a local cache which is updated on submit of usefulness, which means it is not perfect. For Oneiric, I've already re-written it to retrieve the usefulness votes from the server for the currently logged in user so it should be more reliable.

In any event, the server should probably stop multiples from being possible.

Revision history for this message
Anthony Lenton (elachuni) wrote :

I agree it shouldn't be the responsibility of the client to prevent the user from submitting multiple usefulness votes for the same review (though if it wants to do so as for some usability enhancement, neat).

On the server side, that bit of code could be rewritten to replace any current usefulness vote(s?) for that user-and-review if there is any.

Revision history for this message
Michael Nelson (michael.nelson) wrote : Re: [Bug 802868] Re: MultipleObjects error when recommending review

On Tue, Jun 28, 2011 at 2:52 PM, Anthony Lenton
<email address hidden>wrote:

>
> On the server side, that bit of code could be rewritten to replace any
> current usefulness vote(s?) for that user-and-review if there is any.
>

It looks as though it is written to do exactly that... I've not yet
investigated how the multiple recommendations have been submitted.

Revision history for this message
Anthony Lenton (elachuni) wrote :

heh, yep, I meant that if there were multiple usefulness votes, the server-side code should replace them all for a single updated usefulness objects.

I was going to say that the only way I could think of that we could be generating multiple usefulness objects with the current code is if two requests come in at the same time to different app servers, but it doesn't seem that the client is currently doing this. Either way it definitely makes sense to look at other possibilities.

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Just removed piston-mini-client as a target (it was of course piston, not mini-client through which the exception was raised... but even then, it's deeper down the stack in django's utils where the string isn't handled).

Changed in piston-mini-client:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.