From 9d8da9902628175b0b92ee25767f042a9bc63b83 Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Mon, 24 Aug 2026 07:32:09 +0200 Subject: [PATCH] =?UTF-8?q?fix(contacts):=20ContactCreate-Typ-Inferenz=20?= =?UTF-8?q?=E2=80=94=20Person-Payloads=20ohne=20explizites=20type=20werden?= =?UTF-8?q?=20nicht=20mehr=20als=20Firma=20abgelehnt=20(Regression=20aus?= =?UTF-8?q?=20BUG-008-Fix=20dada44c);=20test=5Fcompanies=2018/18,=20test?= =?UTF-8?q?=5Fcontacts=208/8=20gr=C3=BCn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/schemas/contact.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/schemas/contact.py b/app/schemas/contact.py index ab2bd87..852557b 100644 --- a/app/schemas/contact.py +++ b/app/schemas/contact.py @@ -75,6 +75,13 @@ class ContactCreate(BaseModel): @model_validator(mode="after") def _require_name_or_firstname(self): """Ensure company has a name or person has a firstname.""" + # Infer type from payload when the caller did not send it explicitly: + # person-like fields (firstname/surname) -> person, otherwise company. + if "type" not in self.model_fields_set: + if self.firstname or self.surname: + self.type = "person" + elif self.name: + self.type = "company" if self.type == "company" and not self.name: raise ValueError("Company contacts require a 'name' field") if self.type == "person" and not self.firstname: