Skip to content

Comments

fix: #6802 prevent 500 internal server error when patching recipe tags#6803

Open
SimeonSouttar wants to merge 3 commits intomealie-recipes:mealie-nextfrom
SimeonSouttar:fix/issue-6802-tag-patching
Open

fix: #6802 prevent 500 internal server error when patching recipe tags#6803
SimeonSouttar wants to merge 3 commits intomealie-recipes:mealie-nextfrom
SimeonSouttar:fix/issue-6802-tag-patching

Conversation

@SimeonSouttar
Copy link

fix: #6802 prevent 500 internal server error when patching recipe tags

What this PR does / why we need it:

This PR fixes a 500 Internal Server Error (TypeError: init() missing 1 required positional argument: 'group_id') that occurs when patching a recipe with new tags via the API.

The issue was caused by RecipeService.patch_one not injecting the current user's group_id into new tags before attempting to update the recipe. The Tag ORM model requires group_id for initialization, but this field is typically excluded from the RecipeTag Pydantic model during patch operations (where exclude_unset=True is used).

Changes:

  • mealie/services/recipe/recipe_service.py: Updated patch_one to iterate over patch_data.tags (if present) and explicitly inject self.user.group_id into any tag that needs it.

Which issue(s) this PR fixes:

Testing

I have added a new integration test case to reproduce the bug and verify the fix.

  • New Test: tests/integration_tests/user_recipe_tests/test_issue_6802_patch_tags.py

  • Verification: Ran the test locally with Python 3.12.

  • Command: pytest tests/integration_tests/user_recipe_tests/test_issue_6802_patch_tags.py

  • Result: PASSED

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

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

Thanks for this! A couple small things:

  • Is it possible to move this to the recipe repo instead of the service? That way we can fix this for updates as well as patches
  • Can we do this for categories/tools too? I'm guessing it's the same issue.
  • Can we move the test to tests/unit_tests/repository_tests/test_recipe_repository.py? (assuming we move the functionality to the repo)

Copy link
Author

@SimeonSouttar SimeonSouttar left a comment

Choose a reason for hiding this comment

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

@michael-genson updated inline with your previous comments

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - 500 Internal Server Error when Patching Recipe Tags

2 participants