Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Purge Group Exports type mismatch #3314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions mealie/services/scheduler/tasks/purge_group_exports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from pathlib import Path

from sqlalchemy import select
from sqlalchemy import DateTime, cast, select

from mealie.core import root_logger
from mealie.core.config import get_app_dirs
Expand All @@ -19,7 +19,7 @@ def purge_group_data_exports(max_minutes_old=ONE_DAY_AS_MINUTES):
limit = datetime.datetime.now() - datetime.timedelta(minutes=max_minutes_old)

with session_context() as session:
stmt = select(GroupDataExportsModel).filter(GroupDataExportsModel.expires <= limit)
stmt = select(GroupDataExportsModel).filter(cast(GroupDataExportsModel.expires, DateTime) <= limit)
results = session.execute(stmt).scalars().all()

total_removed = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tempfile
from pathlib import Path

from mealie.repos.repository_factory import AllRepositories
from mealie.schema.recipe.recipe import Recipe
from mealie.services.recipe.recipe_bulk_service import RecipeBulkActionsService
from mealie.services.scheduler.tasks.purge_group_exports import purge_group_data_exports
from tests.utils.factories import random_int, random_string
from tests.utils.fixture_schemas import TestUser


def test_purge_group_exports(database: AllRepositories, unique_user: TestUser):
# create the export
group = database.groups.get_one(unique_user.group_id)
assert group
user = database.users.get_one(unique_user.user_id)
assert user
recipe_exporter = RecipeBulkActionsService(database, user, group)
recipes = [
database.recipes.create(Recipe(name=random_string(), group_id=group.id)) for _ in range(random_int(2, 5))
]

with tempfile.NamedTemporaryFile() as tmpfile:
recipe_exporter.export_recipes(Path(tmpfile.name), [recipe.slug for recipe in recipes])

exports = recipe_exporter.get_exports()
assert len(exports) == 1
export = exports[0]
export_path = Path(export.path)
assert export_path.exists()

# purge the export and confirm all data is removed
purge_group_data_exports(-525600) # 1 year into the future

assert not export_path.exists()
exports = recipe_exporter.get_exports()
assert not exports