Skip to content

readable_from_unique_id crashes on prefixed IDs from generate_unique_id #88

@dennisthemenacing

Description

@dennisthemenacing

Opened on behalf of @BeckettFrey

Bug

generate_unique_id accepts an optional prefix parameter and returns strings like prefix_YYYYMMDD_HHMMSS_ffffff. However, readable_from_unique_id always parses its input with the format %Y%m%d_%H%M%S_%f, meaning any prefixed ID will raise a ValueError.

Location: src/voxkit/storage/utils.py — lines 48–72

Reproduction

from voxkit.storage.utils import generate_unique_id, readable_from_unique_id

prefixed_id = generate_unique_id(prefix="test")
# e.g. "test_20260413_140000_123456"

readable_from_unique_id(prefixed_id)
# ValueError: time data 'test_20260413_140000_123456' does not match format '%Y%m%d_%H%M%S_%f'

Impact

No callers currently use the prefix, so this is latent — but the public API advertises prefix support and a downstream caller using it would hit an unhandled crash.

Suggested fix

Have readable_from_unique_id strip a leading <prefix>_ before parsing, or document/enforce that prefixed IDs are not compatible with readable_from_unique_id. The simplest option:

def readable_from_unique_id(date_str: str) -> str:
    # Strip optional prefix: everything before the first 8-digit date segment
    parts = date_str.split("_")
    # Find the first part that looks like a date (8 digits)
    for i, part in enumerate(parts):
        if len(part) == 8 and part.isdigit():
            date_str = "_".join(parts[i:])
            break
    dt = datetime.strptime(date_str, "%Y%m%d_%H%M%S_%f")
    return dt.strftime("%B %d, %Y at %I:%M:%S %p")

A corresponding test should also be added to tests/storage/test_utils.py to cover the prefixed-ID round-trip.

Metadata

Metadata

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