Skip to content

Decouple YouTube live stream updates from request/response in edit_match admin view#173

Open
goodtune wants to merge 8 commits intomainfrom
claude/issue-172-20250808-2336
Open

Decouple YouTube live stream updates from request/response in edit_match admin view#173
goodtune wants to merge 8 commits intomainfrom
claude/issue-172-20250808-2336

Conversation

@goodtune
Copy link
Owner

@goodtune goodtune commented Aug 9, 2025

Fixes #172

This PR decouples YouTube live stream updates from the request/response cycle in the edit_match admin view by switching from callback functions to Django signal handlers.

Changes

  • Move YouTube API logic from pre_save_callback to Django signal handler
  • Replace request.build_absolute_uri() with Site model for URL generation
  • Add handle_match_youtube_updates signal connected to Match pre_save
  • Remove pre_save_callback and related imports from admin.py

Benefits

  • All Match saves now trigger YouTube updates, not just admin edits
  • YouTube operations are decoupled from HTTP request context
  • No model changes required
  • Existing tests should continue to pass

Generated with Claude Code

…tch admin view

- Move YouTube API logic from pre_save_callback to Django signal handler
- Replace request.build_absolute_uri() with Site model for URL generation
- Add handle_match_youtube_updates signal connected to Match pre_save
- Remove pre_save_callback and related imports from admin.py
- Add proper null checking for play_at field in signal handler
- Fix video links appending logic in signal handler

This decouples YouTube operations from the admin view request/response
cycle while maintaining the same functionality. All Match saves will
now trigger YouTube updates via signal handlers instead of callbacks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Gary Reynolds <goodtune@users.noreply.github.com>
goodtune

This comment was marked as resolved.

@claude

This comment was marked as outdated.

- Move set_youtube_thumbnail import to top of signals/matches.py
- Rename handle_match_youtube_updates to match_youtube_sync
- Update all references in __init__.py and apps.py

Co-authored-by: Gary Reynolds <goodtune@users.noreply.github.com>
@goodtune

This comment was marked as outdated.

@claude

This comment was marked as outdated.

Move set_youtube_thumbnail import inside match_youtube_sync function to avoid circular dependency between signals and tasks modules.

Co-authored-by: Gary Reynolds <goodtune@users.noreply.github.com>
@goodtune

This comment was marked as outdated.

@claude

This comment was marked as outdated.

@goodtune

This comment was marked as outdated.

@claude

This comment was marked as outdated.

- Add new YouTubeSignalHandlerTests class with 8 test cases covering all signal handler scenarios
- Test guard clause, broadcast creation/update/deletion, video management, and title formatting
- Update existing admin tests to mock and verify signal handler execution
- Properly mock YouTube API calls and verify task queuing behavior
- Replace references to old pre_save_callback with signal handler in test comments

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Gary Reynolds <goodtune@users.noreply.github.com>
@goodtune goodtune self-assigned this Aug 11, 2025
goodtune and others added 4 commits September 26, 2025 18:01
Conflicts:
- tournamentcontrol/competition/admin.py
- tournamentcontrol/competition/tests/test_competition_admin.py
Resolved merge conflict by integrating template-based YouTube live stream functionality from #206 into the signal handler approach from #172.

Changes:
- Removed `pre_save_callback` from `edit_match` admin view
- Updated `match_youtube_sync` signal handler to use template rendering
- Added hierarchical template fallback for title and description
- Added safety check for `start_time is None`
- Removed unused `render_to_string` import from admin.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add generic exception handler in `match_youtube_sync` for API errors
- Generate fallback competition URL when match has no PK yet
- Fix mock paths to use `tournamentcontrol.competition.tasks` instead of signals module
- Add `@override_settings(ROOT_URLCONF)` to test classes for proper URL resolution
- Update test fixtures to bypass signals during setup to test specific save scenarios
- Add admin URLs to test `urlpatterns` for complete integration testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple YouTube live stream updates from request/response in edit_match admin view

1 participant