Files
StarPunk/docs/design/v2.6.5/2026-11-01-micropub-media-fixes.md
T
PhilandClaude Opus 5.5 a551770c76 fix: Replies and photo posts read as the right post type (v2.6.5)
Checked rendered pages with mf2py against W3C Post Type Discovery:

- Note pages put u-in-reply-to inside a bare h-cite, making it the
  h-cite's property, so replies parsed as notes (or photo posts). The
  reply context is now the entry's u-in-reply-to h-cite.
- Home page previews had no reply markup; they now show "In reply to"
  with u-in-reply-to.
- Previews always emit e-content, so a text-free photo post can't get
  an implied name.
- Text-free page titles follow PTD order (Repost, Like, Reply, Photo).

tests/test_post_types.py runs PTD on parsed note pages and the home page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 10:06:44 -07:00

3.9 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

  1. Failed creates left a post behind. handle_create made the note, then attached photos. Listing one photo twice broke the note_media unique key, so the client got a 500 while the note stayed published without photos. A retry would post it twice.
  2. Then the database stayed locked. attach_media_to_note didn't roll back, and ConnectionPool.return_connection pooled the connection with its write transaction still open. Other requests got "database is locked" until the 10 s timeout.
  3. Photo posts needed text. The Micropub spec doesn't require content, and q=config advertised a photo post type with only photo, yet creates without content got 400 "Content is required".

Changes

  • database/pool.py: return_connection rolls back an open transaction (or closes the connection if that fails).
  • media.py: attach_media_to_note rolls back on error.
  • micropub.py:
    • handle_create resolves photos (by media URL, downloading remote ones) before create_note. If attaching or crosspost selection fails, it hard-deletes the note before answering 500.
    • _resolve_photos skips repeated media.
    • Content is optional when photos resolve. Content-less posts whose photos all fail still get a 400 from create_note.
    • handle_update allows replace: {content: [""]} and delete: ["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_note and update_note take has_media, so empty content is allowed for photo posts.
  • syndication.py: compose_text drops 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-to was inside a bare h-cite, so it was the h-cite's property, not the entry's. note_preview.html had no reply markup at all. Fixed: the blockquote is u-in-reply-to h-cite (with u-url inside), and previews show "↩ In reply to" with u-in-reply-to.
  • Implied names were possible. Previews left out e-content for posts without text. They worked only because the author h-card blocked an implied name. Previews now always emit e-content.
  • Page title for text-free posts follows PTD order: Repost, Like, Reply, Photo.

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)

  • Photos without alt text render alt="Image", so parsers report alt text nobody wrote (q=source correctly returns "").

  • More than 4 photos are still cut to 4 without an error (ADR-057).

  • video and audio are ignored. This is allowed by the spec, and they aren't in q=config post-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.