Skip to content

Conversation

@SylvainChevalier
Copy link
Contributor

Add [dev] or [play] prefix to email subjects when running in dev or play environments to help distinguish them from production emails.

Changes

  • Modified send_email_with_template() to add prefix based on METACULUS_ENV
  • Created get_email_subject_with_env_prefix() helper for direct EmailMessage usage
  • Applied helper to all EmailMessage instances in utils/tasks.py and misc/views.py

Fixes #3899

Generated with Claude Code

Add [dev] or [play] prefix to email subjects when running in dev or play
environments to help distinguish them from production emails.

Changes:
- Modified send_email_with_template() to add prefix based on METACULUS_ENV
- Created get_email_subject_with_env_prefix() helper for direct EmailMessage usage
- Applied helper to all EmailMessage instances in utils/tasks.py and misc/views.py

Fixes #3899

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

Co-Authored-By: Sylvain <[email protected]>
@SylvainChevalier
Copy link
Contributor Author

Feel free to reject if this adds too much complexity or is too hard to maintain or etc.

@hlbmtc
Copy link
Contributor

hlbmtc commented Dec 10, 2025

@claude I don't like the solution at all. Implement it globally in one place only -- send_email_async

@claude
Copy link

claude bot commented Dec 10, 2025

Claude finished @hlbmtc's task in 5m 3s —— View job


Refactoring Complete ✓

I've successfully refactored the implementation to centralize all email prefix logic in misc/tasks.py as requested.

Changes Made

Single source of truth in misc/tasks.py:

  • Created add_env_prefix_to_subject() function (lines 12-17) - the single place where prefix logic lives
  • Modified send_email_async() to use this function (line 39)

Cleanup across codebase:

  • Removed duplicate prefix logic from utils/email.py
  • Removed get_email_subject_with_env_prefix() helper from utils/tasks.py
  • Updated all 6 EmailMessage instances in utils/tasks.py to use the centralized function
  • Updated both EmailMessage instances in misc/views.py to use the centralized function

Result: All email prefix logic now lives in one place (misc/tasks.py), making it easy to maintain and modify.

Tests: Verified existing tests only mock send_email_async and don't reference the old helper, so no test updates needed.


Branch: claude/issue-3899-20251210-1048

Move all environment prefix logic to a single function in misc/tasks.py:
- Created add_env_prefix_to_subject() as the single source of truth
- Updated send_email_async() to use this function
- Removed duplicate logic from utils/email.py and utils/tasks.py
- Updated all EmailMessage instances to use the centralized function

This simplifies maintenance by keeping all email prefix logic in one place.

Co-authored-by: Hlib <[email protected]>
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.

dev and play environment emails should say [dev] and [play] in the subject

3 participants