-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
Issue with removing videos off of playlist #2814
Comments
I'm also getting this same error on the piped.projectsegfau.lt instance:
The error says something about a duplicate key value, but for reference, the video(s) I try to remove are only shown once in the playlist. Or maybe the 'duplicate key value' has something to do with the playlist ID itself? I'm not sure. I also only started seeing this error since a couple days ago as @sk471onn mentioned. This seems to be a backend error, but just in case it matters: |
Same issue on my personal instance |
I had a look at this today and I think I found the issue. It is caused by TeamPiped/Piped-Backend#672 and more specifically by the logic that is intended to decrease the playlist positioning for every element in the playlist that was positioned after the removed video: The problem is that PostgreSQL does not seem to allow this kind of query as the uniqueness of the primary key constraint is checked after each updated row, not after the completion of the statement. I solved that in my instance by defining the primary key as More information:
Executing the following Statement against my Piped DB solved the issue: ALTER TABLE "playlists_videos_ids" DROP CONSTRAINT "playlists_videos_ids_pkey";
ALTER TABLE "playlists_videos_ids" ADD PRIMARY KEY ("playlist_id", "videos_order") DEFERRABLE INITIALLY IMMEDIATE; Note: I do not know whether this has unintended side effects and it may cause your DB to not being updateable in the future with the official DB migration scripts - so use with caution. @FireMasterK: Maybe you can double-check my analysis/solution and see if it makes sense to include this change? |
Im dealing with this issue too. After updating the database container to
|
Could you please check what version of the postgres image is used? We used to use the Alpine Linux images previously, and they had data consistency issues in regard to unique constraints. |
sorry, it was postgres13 alpine, and after update to postgres15 (not alpine tag) the bug came back next day. |
I ran into this issue with the 13-alpine version, then migrated to 15 (no alpine), error contributed to occur. After troubleshooting I arrived at the conclusion described above. Maybe the 15 version does by default organize the pages on disk differently or there is another reason why it is not occurring more often, but from my research into the inner workings of postgres regarding update statements and primary key constraints the current form of the update statement is expected to fail in cases where postgres does not perform the order decrement in exactly the ascending order. |
I'm using Postgres version 12.16 from Docker's |
We should add a test for this first in https://github.com/TeamPiped/Piped-Backend/blob/master/testing/api-test.sh 🤔 |
I tried this in TeamPiped/Piped-Backend#698, but the test seems to pass. Perhaps we have something else wrong? |
I also have this issue. I've been looking at it and I don't think it's as simple as having a playlist and removing a single video - I tried that on the official instance and it seems to work. I can say that for small playlists, this hasn't been an issue for me, but when I have larger ones, this problem shows up. I'd like to say around 20-30+ videos on a playlist. And yes, the problem becomes deleting the older ones. You can do it, but you have to delete the newer ones first, and work your way backwards. I'm using Postgres 15 (not the alpine version) |
I've tried upgrading from 13-alpine to 15 (non alpine) but no luck. I think it's something to do with having the same video multiple times in the one playlist but can't figure out how to replicate it. Full Error
|
I‘m experience the same issue on a hosted instance. |
In my testing duplicate videos are also what triggers the issue. |
That wasn’t the case for my playlists. It only contained each video once and also not in another playlist. On 29 Oct 2023, at 17:18, Jonathan Treffler ***@***.***> wrote:
I think it's something to do with having the same video multiple times in the one playlist but can't figure out how to replicate it.
In my testing duplicate videos are also what triggers the issue.
In my opinion duplicate videos in playlists should not even be a thing and a request to add a video to a playlist a second time should be rejected.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
I also did not experience this.
FWIW, I've been rocking this change for months and it seems to work great. Thank you @leepfrog-ger! |
Somehow missed that comment, it also looks to have sorted the issue for me 🎉 |
Just want to echo that this worked for me. Thanks @leepfrog-ger! |
Outta curiosity - has this "fix" been rolled into main version yet? As it seems I'm now seeing this on ggtyler.dev, where I accidentally got the same video added twice to a playlist, and I now I cannot delete either of them without triggering the error. |
I don’t think it has. Fwiw it is still working (for me) with the most recent version. |
Ok thx, seems I was the lucky one! To anyone else having this issue, my "workaround" to resolve it was to:
If anyone knows a quicker workaround (in case this happens again), I'm all ears 🤓 |
Sigh, I spoke too soon. This one is weirder, because there is no duplication of videos that I can see (I also double-checked the export for dupes), but still when I try to remove some videos, I get...
|
@FireMasterK @Bnyro maybe you could take another look at the analysis/suggestion I posted here: #2814 (comment) It seems clear that this is a widespread issue and no valid use of postgresql prone to intermittent failures |
I feel it may simply be caused by an incorrect connection handling setting in https://github.com/TeamPiped/Piped-Backend/blob/c746794d7434d0cda99f8b586a431ef69e1fb7b5/src/main/resources/hibernate.cfg.xml#L13 The valid settings are https://docs.jboss.org/hibernate/orm/6.4/javadocs/org/hibernate/resource/jdbc/spi/PhysicalConnectionHandlingMode.html I feel I just haven't had enough time to look into that, unfortunately. I'll take a look over the weekend if I can. |
Thanks! I did some further research and wanted to add the results here, too. This comment even provides a dbfiddle where the issue can be reproduced: |
Is this not a widespread issue? |
Thanks for that solution! I'm not that much of a nerd of doing stuff like this around here but where do I put this statement? Is it in like some sort of pat of the code or do i have to put it else where? |
This is an SQL statement that needs to be executed against the postgresql database that is running in the db container. |
Hey there, unsure if you've figured it out by now but allow me to document my process for implementing this (I literally only just got this fix running so it's worked for a lengthy 10 minutes now).
This should output a list of databases, the important one in this case is named "piped" by default.
So far, so good. Hoping this works long term. |
This happens due to Postgres not executing the updates in expected order. The query that causes the error The easiest way to work around the problem is to make the constraint that causes the error deferrable (@leepfrog-ger 's solution). I'd only use I can create a PR with a Liquibase changeset that recreates the constraint just for Postgres, if everyone is OK with that. |
Fixes the constraint violation error upon removing a video from a playlist with PostgreSQL Resolves TeamPiped/Piped#2814
Fixes the constraint violation error upon removing a video from a playlist with PostgreSQL Resolves TeamPiped/Piped#2814
Official Instance
Describe the bug
I have a private instance and have a playlist with 30 videos or so on my account. The videos are all distinct (no duplicates). On this playlist, attempting to remove some videos fails with a database error (see logs below).
Some videos, however, do delete just fine. Seemingly, it's the videos that were added last to the playlist (the last couple of them) that don't display this behavior, while the videos that were added earlier do.
I suspect the amount of videos on the playlist might also play a part on this as I did a test where I deleted the videos that never displayed an error, and then attempted to delete the videos that previously erred, and they deleted fine.
For some context on timelines, I start seeing the error on videos added about 2 days ago.
I did a quick sanity test with the below reproduction steps on the official instance and wasn't able to replicate the issue, unfortunately.
To Reproduce
As mentioned, you might not see the error specifically with these reproduction steps. Playlist video count and time since added may play into this problem.
Expected behavior
No error, video is removed from the playlist
Logs/Errors
Here's the full error as displayed in the backend server:
I am running the backend on commit
69757fd
.Browser, and OS with Version.
Brave Version 1.56.20
Windows 11 22H2 22621.2134
Additional context
No response
The text was updated successfully, but these errors were encountered: