fix(backend): resolve pytest/FastAPI/Pydantic deprecation warnings and fix shallow-copy mutation bug - #324
Merged
Merged
Conversation
…d fix shallow-copy mutation bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 leftmock.breeding_type_and_quantitypointing at the same nested object as the originalapr. Rendering a "missing quantity" panel then mutated the placeholder quantity (EggQuantity.from_count(1)) onto that shared object, silently corrupting the originalAnimalPainReportit was supposed to leave untouched. Addedtest_knowledge_panel_generator_missing_quantity_does_not_mutate_original_pain_reportas a regression test (verified it fails without the fix).app/main.py: replaced the deprecated@app.on_event("shutdown")with alifespancontext manager, per FastAPI's current guidance.pyproject.toml: setasyncio_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 setmock_response.raise_for_status = AsyncMock(...), butraise_for_status()is called synchronously (never awaited) in the real code - calling that mock produced an un-awaited-coroutineRuntimeWarning. Changed toMock(...), 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).