Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
17.10.13, 18.4.6, 18.8.0
-
None
-
Unknown
-
Description
When a file is uploaded through the attachment picker (XWiki.AttachmentSelector, e.g. the avatar picker of the user profile), the field can end up set to another attachment of the page instead of the file that was just uploaded. This happens when the uploaded file and another attachment of the same page have the same upload date at the second level (e.g. two uploads within one second).
Steps to reproduce
- Edit your user profile and click the avatar to open the attachment picker.
- Upload avatar.png: it becomes the avatar.
- Within the same second (easiest with an automated test, e.g. UserProfileIT#changeAvatarImage), open the picker again and upload avatar2.png.
Actual result
The avatar is still avatar.png: the second upload is stored as an attachment but not selected.
Expected result
The avatar is avatar2.png, the file that was just uploaded.
Technical cause
- The picker submits the upload form with an xredirect to AttachmentSelector?xaction=postUpload. postUpload does not know which file was uploaded: it sorts the target document's attachments by date:desc and saves the first one's name in the field.
- XWikiAttachment#setDate drops the milliseconds ("for consistency with the database"), so attachments uploaded in the same second have equal dates.
- The sort is stable and getAttachmentList() is ordered by file name, so on a tie the alphabetically first attachment wins (avatar.png before avatar2.png).
postUpload should select the attachment that was actually uploaded (e.g. pass its file name through the xredirect URL from the picker), and fall back to the newest attachment only when that name is absent.