Order of media attachments not preserved when creating a status
opened this issue · comments
When attaching multiple media attachments to a post on a Takahe instance, the order of attachment is sometimes not preserved.
While I have not tested this myself, it appears that Mastodon preserves the order of media attachments (as per mastodon/mastodon#5857).
I initially was not sure if this was a client issue, and so made the script below for confirmation. The order of media_attachments
returned when creating a status is sometimes different to the order in the creation request.
Python script
import requests
from collections import OrderedDict
SERVER = "<snip>"
TOKEN = "<snip>"
filename_lookup = OrderedDict()
headers = {
'Authorization': f'Bearer {TOKEN}',
}
filenames = ["twin_peaks.png",
"guinea_pig.png",
"map.png",
"menu.png"]
for filename in filenames:
f = {
'file': open(filename, 'rb'),
}
tmp = requests.post(f'{SERVER}/api/v1/media', headers=headers, files=f)
m_id = tmp.json()["id"]
filename_lookup[m_id] = filename
files = [("media_ids[]", (None, m_id)) for m_id in filename_lookup]
files.append(("status", (None, "text")))
response = requests.post(f'{SERVER}/api/v1/statuses', headers=headers, files=files)
attached_ids = [a["id"] for a in response.json()["media_attachments"]]
attached_files = [filename_lookup[x] for x in attached_ids]
assert filenames == attached_files
There is no ordering in Takahē for attachments other than the natural ordering in the PostgreSQL database, so this is not surprising. Fixing it would require adding an explicit ordering column.