Uncaptioned photos rendered alt="Image", which mf2 parsers report as the photo's alt text. They now take the post's text (excerpt, up to 150 characters), falling back to "Image" only for text-free posts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4.2 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.
Post types (IndieWeb standards check)
Post Type Discovery (W3C Note) has no separate "photo" type to store. A post
with a valid photo is a photo post, unless it's first a repost, like or
reply (step order: repost, like, reply, video, photo). Otherwise it's a note,
or an article when its name isn't a prefix of its content. h-entry treats
u-photo as the primary content, with name as a caption. mf2 implies a
name only when an entry has no other p-*/e-* properties and no nested
microformats.
StarPunk already stores photo posts as notes with media and renders
u-photo outside e-content, which is what the standards ask for. Checking
the rendered pages with mf2py found:
- Replies weren't replies. In
note.html,u-in-reply-towas inside a bareh-cite, so it was the h-cite's property, not the entry's.note_preview.htmlhad no reply markup at all. Fixed: the blockquote isu-in-reply-to h-cite(withu-urlinside), and previews show "↩ In reply to" withu-in-reply-to. - Implied names were possible. Previews left out
e-contentfor posts without text. They worked only because the author h-card blocked an implied name. Previews now always emite-content. - Page title for text-free posts follows PTD order: Repost, Like, Reply, Photo.
Photos without a caption take the post's text as alt (partials/media.html
fallback_alt) instead of the made-up "Image". The Micropub q=source
still reports the stored caption ("").
tests/test_post_types.py parses note pages and the home page with mf2py and
runs PTD for notes, articles, photo posts (no text, caption, title), replies
(with and without a photo) and reposts.
Not changed (noted for later)
-
Text-free photos without alt text still render
alt="Image". Captioned photos use their caption, and others now use the post's text (display_mediafallback_alt, the excerpt cut to 150 characters). -
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.