Files
StarPunk/docs/design/v2.6.5/2026-11-01-micropub-media-fixes.md
T
PhilandClaude Opus 5.5 d0bfc80c2e fix: Micropub photo posts and failed creates (v2.6.5)
- 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>
2026-11-01 09:50:30 -07:00

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

  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.

Not changed (noted for later)

  • 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.