Skip to content

get_event_thumbnail corrupts event IDs containing "e-" #810

@JasSmiths

Description

@JasSmiths

I ran into this while trying to fetch thumbnails for UniFi Protect smart detect events.

get_event_thumbnail() can return None for a perfectly valid event thumbnail if the event ID itself contains the substring e-.

The issue seems to be here:

# old thumbnail URL use thumbnail ID, which is just `e-{event_id}`
thumbnail_id = thumbnail_id.replace("e-", "")

Because str.replace() removes every occurrence, it can change the actual UUID, not just strip the old leading e- prefix.

For example:

event_id = "4e66c92c-d2d3-4c1a-a4be-da7d517de006"
event_id.replace("e-", "")
# "4e66c92c-d2d3-4c1a-a4bda7d517de006"

That means get_event_thumbnail(event_id) ends up requesting the wrong event thumbnail URL and returns None, even though the direct endpoint works:

await api.api_request_raw(f"events/{event_id}/thumbnail")
# returns a JPEG

await api.get_event_thumbnail(event_id)
# returns None because the event ID has been changed

I believe the same problem exists in get_event_animated_thumbnail() as well, since it uses the same replace("e-", "") logic.

Suggested fix:

thumbnail_id = thumbnail_id.removeprefix("e-")

Or, if older Python support is needed:

if thumbnail_id.startswith("e-"):
    thumbnail_id = thumbnail_id[2:]

A useful test case would be an event ID that already contains e- somewhere inside the UUID, plus the old-style prefixed form:

assert strip_thumbnail_prefix("4e66c92c-d2d3-4c1a-a4be-da7d517de006") == "4e66c92c-d2d3-4c1a-a4be-da7d517de006"
assert strip_thumbnail_prefix("e-4e66c92c-d2d3-4c1a-a4be-da7d517de006") == "4e66c92c-d2d3-4c1a-a4be-da7d517de006"

I'm seeing this with uiprotect 10.4.1, and the same code appears to still be present on main.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions