Skip to content
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

Order of media attachments not preserved when creating a status #673

Open
ghost opened this issue Dec 1, 2023 · 1 comment
Open

Order of media attachments not preserved when creating a status #673

ghost opened this issue Dec 1, 2023 · 1 comment
Labels
area/api The OAuth/client app API bug Something isn't working pri/low Low Priority

Comments

@ghost
Copy link

ghost commented Dec 1, 2023

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

images.tar.gz

@ghost ghost changed the title Order of media attachments not preserved Order of media attachments not preserved when creating a status Dec 1, 2023
@andrewgodwin
Copy link
Member

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.

@andrewgodwin andrewgodwin added bug Something isn't working area/api The OAuth/client app API pri/low Low Priority labels Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api The OAuth/client app API bug Something isn't working pri/low Low Priority
Projects
None yet
Development

No branches or pull requests

1 participant