-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Duplicate media on upload after retry #13427
Comments
This is probably not related, but I thought I'd better drop a comment just to be sure. When we were dealing with posts being duplicated after retry, we came to a conclusion that it cannot be prevented without making changes to the API. If the app sends a POST request and goes offline, the server will still process the request. However, the app will never receive a response so it assumes the request failed. Retry will send the same request again - however, since the post doesn't exist on the server yet, it doesn't have remote ID so it's treated by the server as a different post => duplicated post gets created. I think it'll probably not be related to this issue, since images/files upload takes a while and the device would need to go offline in the exact right moment (the last byte was sent but the server didn't send a response yet). |
Thanks @malinajirka !
This is exactly what is happening in this case. This is how I verified:
I could see duplicate images issue even for a post with id.
Looks like same conclusion applies in this case. |
Investigated this issue to see if anything can be done on the client side to fix this issue. Tried a couple of strategies to see if it would help
Both the approaches while may seem to help solve the issue are found to be undue overhead for the task. Need to find out if there's an easier and better option on the backend! cc: @ashiagr, @malinajirka |
@hannahtinkler for your reference about this issue |
Hi @ravishanker!
With regards to this, would the app know the IDs for the failed media items? I may have misunderstood, but if we're talking about the 'ID' field in the example response then I'd expect this would be generated in MySQL so the app wouldn't be aware of it until a successful upload response is returned. You might be referring to something on the app side that is pre-determined and a fixed value though? If you're looking for minimal-change solution, you could create the media item with an alternative Otherwise, I don't see a nice way to do this unless the API and app can agree on an identifier by which to reference the upload. Since you can't guarantee receiving the API response, the app would have to be responsible for setting this. If you can assign and persist a unique identifier to a media item prior to upload, you could provide a way for either the app or the API to identify if a specific item has already been uploaded, either by storing the unique identifier as postmeta on the media item and either:
Obviously media items have a GUID (which feels analogous to a unique identifier), but at the moment it changes per retry and there's also no behaviour in the API or database to prevent duplicate GUIDs from existing. Adding this behaviour would be likely to cause issues, which makes me think postmeta would be a better place to store a unique identifier for this purpose - I suspect the performance wouldn't be amazing though due to the volume of data a postmeta query would have to filter through. Other options that came to mind that I like less:
|
Looked at implementing a couple of options. Particularly, deleting image/s before uploading on retry. Also, marking status with connection error on media. Haven't been able to do it satisfactorily and other priorities have taken over meanwhile. |
Possibly related/similar issue:
|
I confirm that the issue is still reproducible on |
Expected behavior
Retrying upload for a previously upload failed image should not result in duplicate images in the media library.
Actual behavior
If you upload more than one images at once and upload fails for an image, then on retrying to upload makes duplicate copies in the media library.
(Tested on a self-hosted site. Might also be reproducible on a simple WP site.)
Steps to reproduce the behavior
Attempt 1: https://cloudup.com/izjkk0AITDc (Duplicate media on timestamp 1:14)
Attempt 2: https://cloudup.com/iydwecO-FxC (Duplicate media on timestamp 1:53)
Tested on [Pixel3 API 27], WPAndroid [16.2-rc-1]
The text was updated successfully, but these errors were encountered: