diff --git a/mealie/routes/handlers.py b/mealie/routes/handlers.py index 209aeb6f8..0f091c788 100644 --- a/mealie/routes/handlers.py +++ b/mealie/routes/handlers.py @@ -25,7 +25,7 @@ def register_debug_handler(app: FastAPI): async def validation_exception_handler(request: Request, exc: RequestValidationError): exc_str = f"{exc}".replace("\n", " ").replace(" ", " ") log_wrapper(request, exc) - content = {"status_code": status.HTTP_422_UNPROCESSABLE_ENTITY, "message": exc_str, "data": None} - return JSONResponse(content=content, status_code=status.HTTP_422_UNPROCESSABLE_ENTITY) + content = {"status_code": status.HTTP_422_UNPROCESSABLE_CONTENT, "message": exc_str, "data": None} + return JSONResponse(content=content, status_code=status.HTTP_422_UNPROCESSABLE_CONTENT) return validation_exception_handler diff --git a/mealie/services/backups_v2/alchemy_exporter.py b/mealie/services/backups_v2/alchemy_exporter.py index 54b5a5802..3b8c0583f 100644 --- a/mealie/services/backups_v2/alchemy_exporter.py +++ b/mealie/services/backups_v2/alchemy_exporter.py @@ -181,7 +181,7 @@ class AlchemyExporter(BaseService): result = { table.name: [dict(row) for row in connection.execute(table.select()).mappings()] - for table in self.meta.sorted_tables + for table in self.meta.tables.values() } return jsonable_encoder(result) @@ -248,11 +248,11 @@ class AlchemyExporter(BaseService): def drop_all(self) -> None: """Drops all data from the database""" - from sqlalchemy.engine.reflection import Inspector + from sqlalchemy import inspect from sqlalchemy.schema import DropConstraint, DropTable, MetaData, Table with self.engine.begin() as connection: - inspector = Inspector.from_engine(self.engine) + inspector = inspect(self.engine) # We need to re-create a minimal metadata with only the required things to # successfully emit drop constraints and tables commands for postgres (based diff --git a/mealie/services/migrations/utils/database_helpers.py b/mealie/services/migrations/utils/database_helpers.py index 80db1acd3..c20028277 100644 --- a/mealie/services/migrations/utils/database_helpers.py +++ b/mealie/services/migrations/utils/database_helpers.py @@ -45,7 +45,7 @@ class DatabaseMigrationHelpers: ) ) - items_out.append(item_model.model_dump()) + items_out.append(item_model) return items_out def get_or_set_category(self, categories: Iterable[str]) -> list[RecipeCategory]: diff --git a/pyproject.toml b/pyproject.toml index e11546142..3c69dec83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,7 @@ dev = [ "types-urllib3==1.26.25.14", "pydantic-to-typescript2==1.0.6", "freezegun==1.5.5", + "httpx2==2.7.0", ] [build-system] @@ -101,6 +102,12 @@ python_classes = '*Tests' python_files = 'test_*' python_functions = 'test_*' testpaths = ["tests"] +filterwarnings = [ + # Suppress unmaintained third-party pyRdfa utcnow() deprecation warning + "ignore::DeprecationWarning:pyRdfa.*", + # Suppress Python 3.12 default SQLite datetime-adapter deprecation warning + "ignore:The default datetime adapter is deprecated as of Python 3.12:DeprecationWarning", +] [tool.coverage.report] skip_empty = true diff --git a/tests/fixtures/fixture_shopping_lists.py b/tests/fixtures/fixture_shopping_lists.py index 4d2323808..e72a57965 100644 --- a/tests/fixtures/fixture_shopping_lists.py +++ b/tests/fixtures/fixture_shopping_lists.py @@ -2,6 +2,7 @@ import pytest import sqlalchemy from pydantic import UUID4 +from mealie.db.models.household.shopping_list import ShoppingList from mealie.schema.household.group_shopping_list import ShoppingListItemCreate, ShoppingListOut, ShoppingListSave from tests.utils.factories import random_string from tests.utils.fixture_schemas import TestUser @@ -89,6 +90,12 @@ def list_with_items(unique_user: TestUser): yield list_model try: + # tests may delete individual items directly; expire just this list's own ORM + # object (not the whole session) so the cascade delete re-reads list_items from + # the database instead of the stale collection captured when it was seeded + orm_list = database.session.get(ShoppingList, list_model.id) + if orm_list is not None: + database.session.expire(orm_list) database.group_shopping_lists.delete(list_model.id) except sqlalchemy.exc.NoResultFound: # Entry Deleted in Test pass diff --git a/tests/integration_tests/user_household_tests/test_group_mealplan.py b/tests/integration_tests/user_household_tests/test_group_mealplan.py index f78b0eb86..1a9cfb858 100644 --- a/tests/integration_tests/user_household_tests/test_group_mealplan.py +++ b/tests/integration_tests/user_household_tests/test_group_mealplan.py @@ -2,6 +2,8 @@ import random from datetime import UTC, datetime, timedelta from uuid import UUID +from dateutil.tz import tzlocal + from fastapi.testclient import TestClient from mealie.schema.household.household import HouseholdSummary @@ -193,7 +195,7 @@ def test_get_mealplan_today(api_client: TestClient, unique_user: TestUser): # Create Meal Plans for today test_meal_plans = [ CreatePlanEntry( - date=datetime.now(UTC).date(), entry_type="breakfast", title=random_string(), text=random_string() + date=datetime.now(tzlocal()).date(), entry_type="breakfast", title=random_string(), text=random_string() ).model_dump() for _ in range(3) ] @@ -212,7 +214,7 @@ def test_get_mealplan_today(api_client: TestClient, unique_user: TestUser): response_json = response.json() for meal_plan in response_json: - assert meal_plan["date"] == datetime.now(UTC).date().strftime("%Y-%m-%d") + assert meal_plan["date"] == datetime.now(tzlocal()).date().strftime("%Y-%m-%d") def test_get_mealplan_with_rules_categories_and_tags_filter(api_client: TestClient, unique_user: TestUser): diff --git a/tests/unit_tests/services_tests/scheduler/tasks/test_create_timeline_events.py b/tests/unit_tests/services_tests/scheduler/tasks/test_create_timeline_events.py index 45b78874f..4786af820 100644 --- a/tests/unit_tests/services_tests/scheduler/tasks/test_create_timeline_events.py +++ b/tests/unit_tests/services_tests/scheduler/tasks/test_create_timeline_events.py @@ -1,6 +1,7 @@ from datetime import UTC, datetime, timedelta from dateutil.parser import parse as parse_dt +from dateutil.tz import tzlocal from fastapi.testclient import TestClient from pydantic import UUID4 @@ -35,10 +36,10 @@ def test_new_mealplan_event(api_client: TestClient, unique_user: TestUser, h2_us response_json = response.json() initial_event_count = len(response_json["items"]) - new_plan = CreatePlanEntry(date=datetime.now(UTC).date(), entry_type="dinner", recipe_id=recipe_id).model_dump( - by_alias=True - ) - new_plan["date"] = datetime.now(UTC).date().isoformat() + new_plan = CreatePlanEntry( + date=datetime.now(tzlocal()).date(), entry_type="dinner", recipe_id=recipe_id + ).model_dump(by_alias=True) + new_plan["date"] = datetime.now(tzlocal()).date().isoformat() new_plan["recipeId"] = str(recipe_id) response = api_client.post(api_routes.households_mealplans, json=new_plan, headers=unique_user.token) @@ -115,10 +116,10 @@ def test_new_mealplan_event_duplicates(api_client: TestClient, unique_user: Test response_json = response.json() initial_event_count = len(response_json["items"]) - new_plan = CreatePlanEntry(date=datetime.now(UTC).date(), entry_type="dinner", recipe_id=recipe_id).model_dump( - by_alias=True - ) - new_plan["date"] = datetime.now(UTC).date().isoformat() + new_plan = CreatePlanEntry( + date=datetime.now(tzlocal()).date(), entry_type="dinner", recipe_id=recipe_id + ).model_dump(by_alias=True) + new_plan["date"] = datetime.now(tzlocal()).date().isoformat() new_plan["recipeId"] = str(recipe_id) response = api_client.post(api_routes.households_mealplans, json=new_plan, headers=unique_user.token) @@ -162,9 +163,9 @@ def test_new_mealplan_events_with_multiple_recipes(api_client: TestClient, uniqu mealplan_count_by_recipe_id[recipe.id] = 0 # type: ignore for _ in range(random_int(1, 5)): new_plan = CreatePlanEntry( - date=datetime.now(UTC).date(), entry_type="dinner", recipe_id=str(recipe.id) + date=datetime.now(tzlocal()).date(), entry_type="dinner", recipe_id=str(recipe.id) ).model_dump(by_alias=True) - new_plan["date"] = datetime.now(UTC).date().isoformat() + new_plan["date"] = datetime.now(tzlocal()).date().isoformat() new_plan["recipeId"] = str(recipe.id) response = api_client.post(api_routes.households_mealplans, json=new_plan, headers=unique_user.token) @@ -231,10 +232,10 @@ def test_preserve_future_made_date(api_client: TestClient, unique_user: TestUser household_recipe = HouseholdRecipeSummary.model_validate(response.json()) assert household_recipe.last_made is None - new_plan = CreatePlanEntry(date=datetime.now(UTC).date(), entry_type="dinner", recipe_id=recipe_id).model_dump( - by_alias=True - ) - new_plan["date"] = datetime.now(UTC).date().isoformat() + new_plan = CreatePlanEntry( + date=datetime.now(tzlocal()).date(), entry_type="dinner", recipe_id=recipe_id + ).model_dump(by_alias=True) + new_plan["date"] = datetime.now(tzlocal()).date().isoformat() new_plan["recipeId"] = str(recipe_id) response = api_client.post(api_routes.households_mealplans, json=new_plan, headers=unique_user.token) diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index 3277d87a1..7e03e3a3d 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -294,7 +294,7 @@ ldap_cases_ids = [x[0] for x in ldap_validation_cases] def test_ldap_settings_validation(data: LDAPValidationCase, monkeypatch: pytest.MonkeyPatch): for setting in data.settings: if setting.value is not None: - monkeypatch.setenv(setting.name, setting.value) + monkeypatch.setenv(setting.name, str(setting.value)) else: monkeypatch.delenv(setting.name, raising=False) @@ -366,7 +366,7 @@ oidc_cases_ids = [x[0] for x in oidc_validation_cases] def test_oidc_settings_validation(data: OIDCValidationCase, monkeypatch: pytest.MonkeyPatch): for setting in data.settings: if setting.value is not None: - monkeypatch.setenv(setting.name, setting.value) + monkeypatch.setenv(setting.name, str(setting.value)) else: monkeypatch.delenv(setting.name, raising=False) diff --git a/uv.lock b/uv.lock index 2efc41a87..9aad06fd3 100644 --- a/uv.lock +++ b/uv.lock @@ -571,6 +571,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" }, ] +[[package]] +name = "httpcore2" +version = "2.7.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "h11" }, + { name = "truststore" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/d5/fe/6a3f9f1a8bb8733326140737446aaf72fddb8b54b8f202302f5c84960613/httpcore2-2.7.0.tar.gz", hash = "sha256:6dc0fedf329a52a990930a5579edfebaea81118ea700ea0dd7de2b5e5be49efc", size = 65593, upload-time = "2026-07-14T20:40:01.111Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6f/6c/62e2e279e63fc4f7a5ee841ef13175a8bbc613f258e9dcc186e9de803a42/httpcore2-2.7.0-py3-none-any.whl", hash = "sha256:1452f589fe23f55b44546cd884294c41a29330af902bc0b71a761fd52d18f92b", size = 81506, upload-time = "2026-07-14T20:39:58.053Z" }, +] + [[package]] name = "httptools" version = "0.8.0" @@ -615,6 +628,22 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/6e/13/82039e3df58e0d52a6f82cc73d958400a2777d78c6cd6378c937a707afd0/httpx_curl_cffi-0.1.5-py3-none-any.whl", hash = "sha256:be414a97ac1f627693f4c8a8631f2852bb1c09456e61ff8ad996ad050a11fb53", size = 8933, upload-time = "2025-12-02T08:59:12.447Z" }, ] +[[package]] +name = "httpx2" +version = "2.7.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "httpcore2" }, + { name = "idna" }, + { name = "truststore" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a3/4a/129b2e21b90ac2985d3928d96792bccc39bc6dfe796c5eee2d8ec06d4105/httpx2-2.7.0.tar.gz", hash = "sha256:8b30709aed5c8465b0dd3b95c09ce301c8f79e7e7a2d00ab0af551e0d0375b07", size = 94487, upload-time = "2026-07-14T20:40:02.318Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1d/b8/c341bba6411bdfda786020343c47a75ef472f6085caf82391b142b1a3ad9/httpx2-2.7.0-py3-none-any.whl", hash = "sha256:ed2a2719c696789e09493bd8e2bec3d8bd925cc6e26b68389ec25ade132f7bf4", size = 90234, upload-time = "2026-07-14T20:39:59.531Z" }, +] + [[package]] name = "identify" version = "2.6.19" @@ -934,6 +963,7 @@ dev = [ { name = "coverage" }, { name = "coveragepy-lcov" }, { name = "freezegun" }, + { name = "httpx2" }, { name = "mkdocs-material" }, { name = "mypy" }, { name = "pre-commit" }, @@ -1004,6 +1034,7 @@ dev = [ { name = "coverage", specifier = "==7.15.3" }, { name = "coveragepy-lcov", specifier = "==0.1.2" }, { name = "freezegun", specifier = "==1.5.5" }, + { name = "httpx2", specifier = "==2.7.0" }, { name = "mkdocs-material", specifier = "==9.7.7" }, { name = "mypy", specifier = "==2.3.0" }, { name = "pre-commit", specifier = "==4.6.1" }, @@ -1908,6 +1939,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f9/1c/01bfd571a64e7f270e6bab5e33777debe0edc56759233ce84f27dec92d14/tqdm-4.70.0-py3-none-any.whl", hash = "sha256:7f585706bfddbdebf89daac705b2dfcc16890130727d3197ca62c732b4310953", size = 80184, upload-time = "2026-07-27T11:33:13.167Z" }, ] +[[package]] +name = "truststore" +version = "0.10.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/53/a3/1585216310e344e8102c22482f6060c7a6ea0322b63e026372e6dcefcfd6/truststore-0.10.4.tar.gz", hash = "sha256:9d91bd436463ad5e4ee4aba766628dd6cd7010cf3e2461756b3303710eebc301", size = 26169, upload-time = "2025-08-12T18:49:02.73Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/19/97/56608b2249fe206a67cd573bc93cd9896e1efb9e98bce9c163bcdc704b88/truststore-0.10.4-py3-none-any.whl", hash = "sha256:adaeaecf1cbb5f4de3b1959b42d41f6fab57b2b1666adb59e89cb0b53361d981", size = 18660, upload-time = "2025-08-12T18:49:01.46Z" }, +] + [[package]] name = "types-python-dateutil" version = "2.9.0.20260716"