File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -260,21 +260,12 @@ class Person(BaseModel):
260260 def test_schema_with_many_fields (self ) -> None :
261261 """Verify key generation handles schemas with many fields."""
262262 # Arrange
263- # Create schema with 50+ fields using proper Pydantic field definition
264- from pydantic import Field
263+ # Create schema with 50+ fields using create_model to avoid polluting BaseModel
264+ from pydantic import create_model
265265
266- fields_dict = {f"field_{ i } " : (str , Field (default = "" )) for i in range (60 )}
267-
268- class LargeSchema (BaseModel ):
269- pass
270-
271- # Dynamically add fields to the model
272- for field_name , field_type in fields_dict .items ():
273- LargeSchema .__annotations__ [field_name ] = field_type [0 ]
274- setattr (LargeSchema , field_name , field_type [1 ])
275-
276- # Rebuild model to process the new fields
277- LargeSchema .model_rebuild ()
266+ # Create a dictionary suitable for create_model
267+ fields_dict = {f"field_{ i } " : (str , ...) for i in range (60 )}
268+ LargeSchema = create_model ("LargeSchema" , ** fields_dict ) # type: ignore # noqa: N806
278269
279270 prompt = "Generate data"
280271 model = "llama-3.1-8b-instant"
You can’t perform that action at this time.
0 commit comments