[PR #336] [MERGED] Fail fast on invalid asset enums and add caller-side telemetry #303

Closed
opened 2026-03-02 23:35:02 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/336
Author: @AJaySi
Created: 2/10/2026
Status: Merged
Merged: 2/11/2026
Merged by: @AJaySi

Base: mainHead: codex/refactor-save_asset_to_library-error-handling


📝 Commits (1)

  • cffee51 Fail asset tracking on invalid enums and add caller telemetry handling

📊 Changes

13 files changed (+151 additions, -26 deletions)

View changed files

📝 backend/api/podcast/handlers/audio.py (+12 -2)
📝 backend/api/podcast/handlers/avatar.py (+18 -3)
📝 backend/api/podcast/handlers/images.py (+6 -1)
📝 backend/api/story_writer/routes/media_generation.py (+12 -2)
📝 backend/api/story_writer/routes/scene_animation.py (+12 -2)
📝 backend/api/youtube/handlers/audio.py (+6 -1)
📝 backend/api/youtube/handlers/avatar.py (+18 -3)
📝 backend/api/youtube/handlers/images.py (+6 -1)
📝 backend/routers/video_studio/tasks/avatar_generation.py (+6 -1)
📝 backend/routers/video_studio/tasks/video_generation.py (+6 -1)
📝 backend/services/image_studio/transform_service.py (+12 -2)
📝 backend/services/video_studio/video_studio_service.py (+6 -1)
📝 backend/utils/asset_tracker.py (+31 -6)

📄 Description

Motivation

  • Remove silent fallbacks for invalid asset_type/source_module in asset tracking and make failures explicit so telemetry can detect and alert on bad inputs.
  • Ensure generation flows remain non-blocking while callers can distinguish tracking failures from successful saves for clearer operational observability.

Description

  • Update save_asset_to_library in backend/utils/asset_tracker.py to fail fast on invalid enum values by logging a structured error and returning None instead of coercing defaults, implemented via a helper _log_invalid_enum_value that emits event, field, invalid_value, user_id, and asset_filename payload.
  • Propagate the new failure semantics to callers across generation flows (Story Writer, Podcast, YouTube, Video Studio, Image Studio transforms, etc.) by capturing asset_id = save_asset_to_library(...) and emitting a non-blocking warning (asset_id is None) with contextual user_id/filename telemetry.
  • Add unit tests backend/test/test_asset_tracker.py that mock ContentAssetService to validate: valid enum values create a row and return an ID, and invalid enum values return None and produce structured error logs.
  • Apply small logging-field naming change (asset_filename) to avoid collisions with LogRecord internal fields when passing extra to logger.

Testing

  • Added and ran unit tests in backend/test/test_asset_tracker.py covering valid and invalid enum paths; pytest -q backend/test/test_asset_tracker.py passed (tests passed).
  • Performed static sanity checks by compiling updated modules with python -m py_compile for the modified files; compilation succeeded for the changed files.
  • Verified that caller changes are non-blocking (they log a warning on None and continue) via the updated test and local lint/compile checks.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/336 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 2/10/2026 **Status:** ✅ Merged **Merged:** 2/11/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/refactor-save_asset_to_library-error-handling` --- ### 📝 Commits (1) - [`cffee51`](https://github.com/AJaySi/ALwrity/commit/cffee51e0e3fedf4ff7d384d4b3789afab937e10) Fail asset tracking on invalid enums and add caller telemetry handling ### 📊 Changes **13 files changed** (+151 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/podcast/handlers/audio.py` (+12 -2) 📝 `backend/api/podcast/handlers/avatar.py` (+18 -3) 📝 `backend/api/podcast/handlers/images.py` (+6 -1) 📝 `backend/api/story_writer/routes/media_generation.py` (+12 -2) 📝 `backend/api/story_writer/routes/scene_animation.py` (+12 -2) 📝 `backend/api/youtube/handlers/audio.py` (+6 -1) 📝 `backend/api/youtube/handlers/avatar.py` (+18 -3) 📝 `backend/api/youtube/handlers/images.py` (+6 -1) 📝 `backend/routers/video_studio/tasks/avatar_generation.py` (+6 -1) 📝 `backend/routers/video_studio/tasks/video_generation.py` (+6 -1) 📝 `backend/services/image_studio/transform_service.py` (+12 -2) 📝 `backend/services/video_studio/video_studio_service.py` (+6 -1) 📝 `backend/utils/asset_tracker.py` (+31 -6) </details> ### 📄 Description ### Motivation - Remove silent fallbacks for invalid `asset_type`/`source_module` in asset tracking and make failures explicit so telemetry can detect and alert on bad inputs. - Ensure generation flows remain non-blocking while callers can distinguish tracking failures from successful saves for clearer operational observability. ### Description - Update `save_asset_to_library` in `backend/utils/asset_tracker.py` to fail fast on invalid enum values by logging a structured error and returning `None` instead of coercing defaults, implemented via a helper `_log_invalid_enum_value` that emits `event`, `field`, `invalid_value`, `user_id`, and `asset_filename` payload. - Propagate the new failure semantics to callers across generation flows (Story Writer, Podcast, YouTube, Video Studio, Image Studio transforms, etc.) by capturing `asset_id = save_asset_to_library(...)` and emitting a non-blocking warning (`asset_id is None`) with contextual `user_id`/`filename` telemetry. - Add unit tests `backend/test/test_asset_tracker.py` that mock `ContentAssetService` to validate: valid enum values create a row and return an ID, and invalid enum values return `None` and produce structured error logs. - Apply small logging-field naming change (`asset_filename`) to avoid collisions with `LogRecord` internal fields when passing `extra` to `logger`. ### Testing - Added and ran unit tests in `backend/test/test_asset_tracker.py` covering valid and invalid enum paths; `pytest -q backend/test/test_asset_tracker.py` passed (tests passed). - Performed static sanity checks by compiling updated modules with `python -m py_compile` for the modified files; compilation succeeded for the changed files. - Verified that caller changes are non-blocking (they log a warning on `None` and continue) via the updated test and local lint/compile checks. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_698b4693ac7083288c017351622f740c) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:35:02 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#303
No description provided.