From bcde3bd9d58964c89b8406b1e5e44099fb0e6ce8 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Wed, 11 Mar 2026 19:04:57 -0700 Subject: [PATCH] Don't construct synthetic objects --- app/routers/contacts.py | 5 ++++- tests/test_contacts_router.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/routers/contacts.py b/app/routers/contacts.py index e84c877..124c698 100644 --- a/app/routers/contacts.py +++ b/app/routers/contacts.py @@ -286,7 +286,10 @@ async def create_contact( if request.try_historical: await start_historical_dm_decryption(background_tasks, lower_key, request.name) - return Contact(**contact_upsert.model_dump()) + stored = await ContactRepository.get_by_key(lower_key) + if stored is None: + raise HTTPException(status_code=500, detail="Contact was created but could not be reloaded") + return stored @router.get("/{public_key}/detail", response_model=ContactDetail) diff --git a/tests/test_contacts_router.py b/tests/test_contacts_router.py index 9af9242..5e8b5b1 100644 --- a/tests/test_contacts_router.py +++ b/tests/test_contacts_router.py @@ -117,11 +117,13 @@ class TestCreateContact: data = response.json() assert data["public_key"] == KEY_A assert data["name"] == "NewContact" + assert data["last_seen"] is not None # Verify in DB contact = await ContactRepository.get_by_key(KEY_A) assert contact is not None assert contact.name == "NewContact" + assert data["last_seen"] == contact.last_seen @pytest.mark.asyncio async def test_create_invalid_hex(self, test_db, client):