- A create that failed after the note was written (e.g. the same photo twice) answered 500 but left the post published without photos. Photos are now resolved first, and a failed note is removed. - Pooled connections roll back unfinished writes, so one failure no longer locks the database for the next ~10 s. - The same photo twice in one post is shown once. - Photo posts no longer need text (Micropub doesn't require content, and q=config already advertised a photo-only post type). Updates may clear the text while photos remain. Crossposts start with the link; the page is titled "Photo". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2.3 KiB
2.3 KiB
v2.6.5: Micropub media fixes
Found while adding media uploads to tuipub, a Micropub client written to the spec rather than to StarPunk.
Problems
- Failed creates left a post behind.
handle_createmade the note, then attached photos. Listing one photo twice broke thenote_mediaunique key, so the client got a 500 while the note stayed published without photos. A retry would post it twice. - Then the database stayed locked.
attach_media_to_notedidn't roll back, andConnectionPool.return_connectionpooled the connection with its write transaction still open. Other requests got "database is locked" until the 10 s timeout. - Photo posts needed text. The Micropub spec doesn't require
content, andq=configadvertised aphotopost type with onlyphoto, yet creates without content got 400 "Content is required".
Changes
database/pool.py:return_connectionrolls back an open transaction (or closes the connection if that fails).media.py:attach_media_to_noterolls back on error.micropub.py:handle_createresolves photos (by media URL, downloading remote ones) beforecreate_note. If attaching or crosspost selection fails, it hard-deletes the note before answering 500._resolve_photosskips repeated media.- Content is optional when photos resolve. Content-less posts whose photos
all fail still get a 400 from
create_note. handle_updateallowsreplace: {content: [""]}anddelete: ["content"]while the note keeps photos (or is a like or repost). Otherwise it answers 400 "A post needs text or a photo".
notes.py:create_noteandupdate_notetakehas_media, so empty content is allowed for photo posts.syndication.py:compose_textdrops the leading blank line when there's no body.
Not changed (noted for later)
- More than 4 photos are still cut to 4 without an error (ADR-057).
videoandaudioare ignored. This is allowed by the spec, and they aren't inq=configpost-types.- Media endpoint errors for non-images expose Python text ("cannot identify image file <_io.BytesIO …>").
Tests
tests/test_micropub_v265.py. The full suite runs with
SESSION_SECRET=test. 8 tests in test_media_upload.py and
test_migration_race_condition.py already fail on main, and still fail here.