Editing a post with media_ids blanks the id and type of its attachments
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
Research direction
Start in PostService around line 473, where the edit path stores DocumentService::mediaAttachmentsForEdit() via Stream::setAttachments(). Compare with StatusAssemblyService, which uses Stream::setMedias() on create, and with StreamMedia::updateAttachmentInList(). Reproduce the six steps in the issue. Done when an edit returns id 103 and type image, and a second edit naming those ids is accepted.
Written by the indexing model from the issue text.
Description
Describe the bug
Editing a post with media_ids (PUT /api/v1/statuses/{id}) blanks every attachment it names: the post is then served with "id": "" and "type": "unknown" for each of them, in the edit's own answer and on every read after it. A later edit that names the ids the post now shows is refused (422 Invalid media attachment list), so a client that edits a post twice cannot keep its media. Naming the original ids again is accepted, but the attachments stay blank.
To Reproduce
On main at 757514521 (0.26.280), as alice, with a direct post so nothing reaches a timeline:
POST /api/v2/mediawith a PNG:{"id": "103", "type": "image", ...}.POST /api/v1/statuseswith{"status": "probe", "media_ids": ["103"], "visibility": "direct"}: the post hasmedia_attachments: [{"id": "103", "type": "image", ...}].PUT /api/v1/statuses/{id}with{"status": "probe edited", "media_ids": ["103"]}: 200,media_attachments: [{"id": "", "type": "unknown", ...}].GET /api/v1/statuses/{id}: the same,"id": "","type": "unknown".PUT /api/v1/statuses/{id}with{"status": "probe edited twice", "media_ids": [""]}(the ids step 4 shows): 422{"error": "Invalid media attachment list"}.PUT /api/v1/statuses/{id}with"media_ids": ["103"]again: 200, still"id": "","type": "unknown".
The same happens with form-encoded media_ids[], first seen on 0.26.279.
Expected behavior
The edited post carries the attachments as a new post does: "id": "103", "type": "image", with their previews and alt text, so the next edit can name them.
Cause, as far as I can tell
On create, StatusAssemblyService hands the documents to Stream::setMedias(). On edit, PostService (around line 473) stores DocumentService::mediaAttachmentsForEdit() with Stream::setAttachments(), and that method builds each attachment with convertToMediaAttachment($this->urlGenerator, ACore::FORMAT_ACTIVITYPUB), so the stored list is the ActivityPub shape: no local id, no Mastodon type. StreamMedia::updateAttachmentInList() documents an earlier bug of this kind ("written out again in the ActivityPub shape, without ids, previews or alt text") and stores convertToMediaAttachment($this->urlGenerator)->asLocal() instead; doing the same here, or going through setMedias() as create does, looks like the fix.
Client details:
- OS: Windows 11, requests sent with Python's
urllib(the same as the Aloha Social Android app sends) - Browser: none
- Version: n/a
- Device: desktop
Server details
Social app version: 0.26.280, main at 757514521
Operating system: Debian (nextcloud-docker-dev)
Web server: Apache 2.4.67
Database: MariaDB 10.6.25
PHP version: 8.5.7
Nextcloud version: 36.0.0 dev
Logs
Nextcloud log (data/nextcloud.log)
Nothing above debug level for these requests.
Browser log
n/a: API requests only.
- Dominant language
- PHP
- Stars
- 499
- Forks
- 59
- PR merge metrics
- No merged PRs in 30d
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
mobile-app
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Open-Locker/Open-Locker#352 ·
Maintainers usually reply within 1 day
-
[Bug]: SCIM Users groups[].value is returned as an integer, causing authentik user discovery to failOpen
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
grokability/snipe-it#20006 ·
Maintainers usually reply within 1 day
-
fixed
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
firefly-iii/firefly-iii#13150 · 2 comments ·
Maintainers usually reply within 1 day
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
TYPO3-Solr/ext-solr#4828 ·
Maintainers usually reply within 5 days