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>
90 lines
4.2 KiB
Markdown
90 lines
4.2 KiB
Markdown
# 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.
|
|
|
|
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_media`
|
|
`fallback_alt`, the excerpt cut to 150 characters).
|
|
|
|
- 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.
|