test(tasks): copre recipe_id nel copy-on-write di create_task (#4)
Sospetto MissingGreenlet su TaskResponse.recipe_id (via RecipeTask.version) quando create_task passa per il copy-on-write - il task appena creato non ha .version precaricato. Test aggiunto: verde, non riproducibile. La lazy load risolve via identity map (new_version è già nella sessione, FK semplice → use_get), senza toccare il DB. Test tenuto come guardia di regressione. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,45 @@ class TestCreateTask:
|
|||||||
assert len(data["subtasks"]) == 1
|
assert len(data["subtasks"]) == 1
|
||||||
assert data["subtasks"][0]["description"] == "Surface roughness"
|
assert data["subtasks"][0]["description"] == "Surface roughness"
|
||||||
|
|
||||||
|
async def test_create_task_on_version_with_measurements_has_recipe_id(
|
||||||
|
self,
|
||||||
|
client: AsyncClient,
|
||||||
|
maker_user: User,
|
||||||
|
measurement_tec_user: User,
|
||||||
|
db_session: AsyncSession,
|
||||||
|
):
|
||||||
|
"""Copy-on-write branch (gitea#4): TaskResponse.recipe_id must not crash."""
|
||||||
|
recipe = await create_test_recipe(db_session, maker_user.id, code="COW-CT")
|
||||||
|
task = (await client.get(
|
||||||
|
f"/api/recipes/{recipe.id}/tasks", headers=auth_headers(maker_user),
|
||||||
|
)).json()[0]
|
||||||
|
subtask_id = task["subtasks"][0]["id"]
|
||||||
|
assert (await _measure(
|
||||||
|
client, measurement_tec_user, subtask_id, task["version_id"]
|
||||||
|
)).status_code == 200
|
||||||
|
|
||||||
|
resp = await client.post(
|
||||||
|
f"/api/recipes/{recipe.id}/tasks",
|
||||||
|
headers=auth_headers(maker_user),
|
||||||
|
json={
|
||||||
|
"title": "New Task After Measurement",
|
||||||
|
"subtasks": [
|
||||||
|
{
|
||||||
|
"marker_number": 1,
|
||||||
|
"description": "Surface roughness",
|
||||||
|
"nominal": 5.0,
|
||||||
|
"utl": 5.5,
|
||||||
|
"ltl": 4.5,
|
||||||
|
"unit": "um",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert resp.status_code == 201, resp.text
|
||||||
|
data = resp.json()
|
||||||
|
assert data["recipe_id"] == recipe.id
|
||||||
|
assert data["version_id"] != task["version_id"]
|
||||||
|
|
||||||
|
|
||||||
class TestUpdateTask:
|
class TestUpdateTask:
|
||||||
"""PUT /api/tasks/{task_id} tests."""
|
"""PUT /api/tasks/{task_id} tests."""
|
||||||
|
|||||||
Reference in New Issue
Block a user