Skip to content

Fix/custom search templates not saved#12155

Closed
Mika3578 wants to merge 8 commits intopymedusa:developfrom
Mika3578:fix/custom-search-templates-not-saved
Closed

Fix/custom search templates not saved#12155
Mika3578 wants to merge 8 commits intopymedusa:developfrom
Mika3578:fix/custom-search-templates-not-saved

Conversation

@Mika3578
Copy link

@Mika3578 Mika3578 commented Feb 5, 2026

This pull request improves how search strings are generated for TV series episodes and seasons, especially when using custom search templates. The main change is that custom templates now strip the year from the series title in search queries, while default templates preserve it. The update also ensures that only default templates are cleaned up when scene exceptions are removed, and only default templates are validated against scene exceptions in the database. Comprehensive tests have been added to verify these behaviors.

Template handling improvements:

  • Custom search templates now strip the year from the series title when generating search strings for episodes and seasons, while default templates retain the year. This is achieved by introducing the get_title_without_year helper and updating the logic in GenericProvider._get_episode_search_strings and GenericProvider._get_season_search_strings. [1] [2] [3]

  • The cleanup logic in SearchTemplates._clean is updated to only remove default templates when their associated scene exception is no longer present, preserving custom templates.

  • The update logic in SearchTemplates.update now always saves custom templates and only validates default templates against the database for the existence of a scene exception.

Testing enhancements:

  • Extensive parameterized tests are added to tests/providers/test_generic_provider.py to verify episode and season search string generation with various combinations of default and custom templates, filtering by season, and template enable/disable states.Fix custom search templates not saved and year in search queries
    Custom search templates not saved (fixes Custom search templates not saved #11024, Cutome search template not saving  #11038)
    Cause: Custom templates were filtered out by the scene exception check in update() and could be removed by _clean().
    Changes in medusa/search_templates.py:
    update(): Skip the scene exception check for custom templates (default=0). Only default templates are validated against scene_exceptions.
    _clean(): Add AND \default\ = 1 so only default templates are deleted. Custom templates are left untouched.
    Year in search queries (Append year to show title)
    Cause: With "Append (year) to each show title" enabled, custom templates could get a title like "Show Name (2024)" from the UI. That value was used in provider search strings, but the year should only be used for folder creation and UI, not for search.
    Changes in medusa/providers/generic_provider.py:
    For custom search templates, use get_title_without_year() when building search strings.
    Default templates still use the original title; their titles already come from series.name without a year.
    Applied for both episode and season search templates.
  • PR is based on the DEVELOP branch
  • Don't send big changes all at once. Split up big PRs into multiple smaller PRs that are easier to manage and review
  • Read the contribution guide

Mika3578 and others added 5 commits February 5, 2026 22:22
…ting default templates against scene exceptions. Update search string handling to strip year from titles for custom templates.
- Test that custom templates (default=0) are preserved even when titles don't match scene exceptions
- Test that default templates (default=1) are removed when scene exceptions are removed
- Test that default templates with show name are always preserved
- Test isolation between multiple shows

Co-authored-by: Mika3578 <[email protected]>
- Extract common mock creation logic into _create_mock_functions helper
- Remove unused monkeypatch_function_return fixture parameter
- All tests still passing

Co-authored-by: Mika3578 <[email protected]>
Copilot AI review requested due to automatic review settings February 5, 2026 22:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes two issues with custom search templates: (1) custom templates were being incorrectly deleted or filtered out, and (2) year suffixes from show titles were being included in search queries for custom templates when they shouldn't be.

Changes:

  • Modified SearchTemplates._clean() to only remove default templates when their scene exceptions are removed, preserving all custom templates
  • Modified SearchTemplates.update() to skip scene exception validation for custom templates, ensuring they're always saved
  • Modified episode and season search string generation in GenericProvider to strip year suffixes from titles in custom templates while preserving them in default templates

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
medusa/search_templates.py Added AND \default` = 1` clause to _clean() to preserve custom templates; modified update() to skip scene exception validation for custom templates
medusa/providers/generic_provider.py Added import of get_title_without_year helper; modified episode and season search string generation to conditionally strip year from custom template titles
tests/test_search_templates.py Added comprehensive tests for template cleanup behavior with default and custom templates
tests/providers/test_generic_provider.py Added parameterized tests for episode and season search string generation with various template configurations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Mika3578
Copy link
Author

Mika3578 commented Feb 5, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

@Mika3578 Mika3578 closed this Feb 8, 2026
@Mika3578 Mika3578 deleted the fix/custom-search-templates-not-saved branch February 8, 2026 12:54
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.

2 participants