Skip to content

fix(backend): resolve pytest/FastAPI/Pydantic deprecation warnings and fix shallow-copy mutation bug - #324

Merged
littlecoffe8 merged 1 commit into
mainfrom
fix/resolve-test-warnings
Aug 22, 2026
Merged

fix(backend): resolve pytest/FastAPI/Pydantic deprecation warnings and fix shallow-copy mutation bug#324
littlecoffe8 merged 1 commit into
mainfrom
fix/resolve-test-warnings

Conversation

@littlecoffe8

Copy link
Copy Markdown
Collaborator

Description

Resolves every warning currently emitted by the test suite (7 → 0). One of them was masking a real bug, fixed here rather than silenced.

Code changes

  • app/business/open_food_facts/panel_renderer/generator.py (bug fix, not just a warning fix): apr.copy()apr.model_copy(deep=True). The old shallow copy left mock.breeding_type_and_quantity pointing at the same nested object as the original apr. Rendering a "missing quantity" panel then mutated the placeholder quantity (EggQuantity.from_count(1)) onto that shared object, silently corrupting the original AnimalPainReport it was supposed to leave untouched. Added test_knowledge_panel_generator_missing_quantity_does_not_mutate_original_pain_report as a regression test (verified it fails without the fix).
  • app/main.py: replaced the deprecated @app.on_event("shutdown") with a lifespan context manager, per FastAPI's current guidance.
  • pyproject.toml: set asyncio_default_fixture_loop_scope = "function" to silence pytest-asyncio's "unset fixture loop scope" deprecation warning (and pin the intended, current default behavior explicitly rather than relying on an implicit one that's changing).
  • tests/app/api/open_food_facts/test_routes.py: 3 pre-existing tests set mock_response.raise_for_status = AsyncMock(...), but raise_for_status() is called synchronously (never awaited) in the real code - calling that mock produced an un-awaited-coroutine RuntimeWarning. Changed to Mock(...), consistent with the other ~10 tests in the same file that already do this correctly.

How to test

cd backend
uv sync --all-groups
uv run pybabel compile -d app/locales
uv run pytest tests/

Before: 110 passed, 7 warnings. After: 111 passed (no warnings line at all).

@littlecoffe8
littlecoffe8 merged commit 2914a4c into main Aug 22, 2026
2 checks passed
@littlecoffe8
littlecoffe8 deleted the fix/resolve-test-warnings branch August 22, 2026 08:05
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.

1 participant