Open-Assistant icon indicating copy to clipboard operation
Open-Assistant copied to clipboard

fix: upsert user reaction instead of inserting

Open croumegous opened this issue 2 years ago • 5 comments

Hello, I played with the end to end demo and saw a bug in the /grading/grade-output page.
If I submit a rating twice the second time I submit it I get the following error in the backend:

sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "post_reaction_pkey"
DETAIL:  Key (post_id, person_id)=(702250a7-0f3b-4469-9e86-ab7de669e832, e5602260-05cf-4a4b-8926-7fe53f09a6dc) already exists.

Indeed we are trying to do an insert instead of an update. I understand that in the end a user may not be supposed to submit a rating twice on the website (page updated once submited).

But depending on the frontend it can be nice to have an update instead (e.g. discord) openassistant_upsert (In the discord example when I try to "update" the rating it failed)

I don't know if this is also nice to have for insert_post, let me know if you want me to also change it.

croumegous avatar Dec 28 '22 00:12 croumegous

Thank you for catching this! Yes, that is a problem i've noticed as well.

fozziethebeat avatar Dec 28 '22 06:12 fozziethebeat

I just rebased my branch with latest commits

croumegous avatar Dec 30 '22 14:12 croumegous

Did you see this?

We have to take notice that updates will invalidate previous entries in the event-journal, e.g. it becomes harder to incrementally compute the item scores .. e.g. we need to query all effective post_reactions and can't rely on the journal data.

the way it looks to me now, even if an update happens, the log_ranking of the journal is still called, e.g. the old reaction log would still be in the journal. I don't have a good overview over the codebase, do you think I'm overlooking something here?

to clarify: if we do upserts, then the journal entries would have to be corrected/updated/replaced accordingly. in general, I'm fine yelling at the user if they submit the rating twice. yes we'll get some mistakes where users change their minds later, but that's life.

yk avatar Jan 02 '23 11:01 yk

I added a new commit to remove the entry in the journal table when we update an existing user reaction.
However, I could understand if you have concerns about implementing this change and prefer to stick with the current behaviour of not allowing upserts. If this is the case I'll just close this PR.

croumegous avatar Jan 02 '23 19:01 croumegous

this is a bit above my competency to decide. @andreaskoepf opinions?

yk avatar Jan 02 '23 21:01 yk