fix(contacts): ContactCreate-Typ-Inferenz — Person-Payloads ohne explizites type werden nicht mehr als Firma abgelehnt (Regression aus BUG-008-Fix dada44c); test_companies 18/18, test_contacts 8/8 grün
This commit is contained in:
@@ -75,6 +75,13 @@ class ContactCreate(BaseModel):
|
|||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def _require_name_or_firstname(self):
|
def _require_name_or_firstname(self):
|
||||||
"""Ensure company has a name or person has a firstname."""
|
"""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:
|
if self.type == "company" and not self.name:
|
||||||
raise ValueError("Company contacts require a 'name' field")
|
raise ValueError("Company contacts require a 'name' field")
|
||||||
if self.type == "person" and not self.firstname:
|
if self.type == "person" and not self.firstname:
|
||||||
|
|||||||
Reference in New Issue
Block a user