@@ -41,6 +41,16 @@ def name_must_not_be_empty(cls, v: str) -> str:
4141SampleModelPartial = make_partial_model (SampleModel )
4242
4343
44+ class ModelWithFieldAttributes (StrictBaseModel ):
45+ """Model with alias, title, and description to test full attribute preservation."""
46+
47+ name : str = Field (alias = "user_name" , title = "User Name" , description = "The user's full name" )
48+ age : int = Field (ge = 0 , le = 150 , title = "Age" , description = "Age in years" )
49+
50+
51+ ModelWithFieldAttributesPartial = make_partial_model (ModelWithFieldAttributes )
52+
53+
4454class TestMakePartialModel :
4555 def test_all_fields_become_optional (self ):
4656 instance = SampleModelPartial ()
@@ -76,3 +86,23 @@ def test_already_optional_fields_stay_optional(self):
7686
7787 def test_partial_model_name (self ):
7888 assert SampleModelPartial .__name__ == "SampleModelPartial"
89+
90+ def test_field_alias_preserved (self ):
91+ instance = ModelWithFieldAttributesPartial (user_name = "Alice" )
92+ assert instance .name == "Alice"
93+
94+ def test_field_title_and_description_preserved (self ):
95+ name_field = ModelWithFieldAttributesPartial .model_fields ["name" ]
96+ assert name_field .alias == "user_name"
97+ assert name_field .title == "User Name"
98+ assert name_field .description == "The user's full name"
99+
100+ age_field = ModelWithFieldAttributesPartial .model_fields ["age" ]
101+ assert age_field .title == "Age"
102+ assert age_field .description == "Age in years"
103+
104+ def test_field_ge_le_constraints_preserved (self ):
105+ with pytest .raises (ValidationError ):
106+ ModelWithFieldAttributesPartial (age = - 1 )
107+ with pytest .raises (ValidationError ):
108+ ModelWithFieldAttributesPartial (age = 200 )
0 commit comments