-
Notifications
You must be signed in to change notification settings - Fork 9
fix: avoid using 'model_config' as a field to support Pydantic v2 #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pydantic v2 treats 'model_config' as a reserved name for configuration. This caused runtime errors during dynamic model creation. Renamed the field to maintain compatibility.
|
Hi, as this has been working fine for … quite some time, can you get me the versions and an MRE to look at? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #348 +/- ##
==========================================
- Coverage 94.80% 94.61% -0.19%
==========================================
Files 88 88
Lines 7468 7507 +39
==========================================
+ Hits 7080 7103 +23
- Misses 388 404 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @commonism, I’ve been working with these packages for over 6 months. I may have recently upgraded FastAPI or another dependency, but suddenly I started getting the errors I addressed in this fix — and it happens with any openapi.json I’m provided. versions are example of json: {
"openapi": "3.1.0",
"info":
{
"title": "FastAPI",
"version": "0.1.0"
},
"servers":
[
{
"url": "http://localhost:8092"
}
],
"paths":
{
"/one_required_query_param":
{
"get":
{
"summary": "One Required Query Param",
"operationId": "one_required_query_param",
"parameters":
[
{
"name": "query_param",
"in": "query",
"required": true,
"schema":
{
"type": "integer",
"title": "Query Param"
}
}
],
"responses":
{
"200":
{
"description": "Successful Response",
"content":
{
"application/json":
{
"schema":
{}
}
}
},
"422":
{
"description": "Validation Error",
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/two_required_query_params":
{
"get":
{
"summary": "Two Required Query Params",
"operationId": "two_required_query_params",
"parameters":
[
{
"name": "query_param_1",
"in": "query",
"required": true,
"schema":
{
"type": "integer",
"title": "Query Param 1"
}
},
{
"name": "query_param_2",
"in": "query",
"required": true,
"schema":
{
"type": "integer",
"title": "Query Param 2"
}
}
],
"responses":
{
"200":
{
"description": "Successful Response",
"content":
{
"application/json":
{
"schema":
{}
}
}
},
"422":
{
"description": "Validation Error",
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/one_required_body_param":
{
"post":
{
"summary": "One Required Body Param",
"operationId": "one_required_body_param",
"requestBody":
{
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/OneBodyParam"
}
}
},
"required": true
},
"responses":
{
"200":
{
"description": "Successful Response",
"content":
{
"application/json":
{
"schema":
{}
}
}
},
"422":
{
"description": "Validation Error",
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/two_required_body_params":
{
"post":
{
"summary": "Two Required Body Params",
"operationId": "two_required_body_params",
"requestBody":
{
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/TwoBodyParams"
}
}
},
"required": true
},
"responses":
{
"200":
{
"description": "Successful Response",
"content":
{
"application/json":
{
"schema":
{}
}
}
},
"422":
{
"description": "Validation Error",
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/one_required_query_param_one_required_body_param":
{
"post":
{
"summary": "One Required Query Param One Required Body Param",
"operationId": "one_required_query_param_one_required_body_param",
"parameters":
[
{
"name": "query_param",
"in": "query",
"required": true,
"schema":
{
"type": "integer",
"title": "Query Param"
}
}
],
"requestBody":
{
"required": true,
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/OneBodyParam"
}
}
}
},
"responses":
{
"200":
{
"description": "Successful Response",
"content":
{
"application/json":
{
"schema":
{}
}
}
},
"422":
{
"description": "Validation Error",
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/dto_object":
{
"get":
{
"summary": "Dto Object",
"operationId": "dto_object",
"requestBody":
{
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/DummyDTO"
}
}
},
"required": true
},
"responses":
{
"200":
{
"description": "Successful Response",
"content":
{
"application/json":
{
"schema":
{}
}
}
},
"422":
{
"description": "Validation Error",
"content":
{
"application/json":
{
"schema":
{
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components":
{
"schemas":
{
"DummyDTO":
{
"properties":
{
"number":
{
"type": "integer",
"title": "Number"
},
"text":
{
"type": "string",
"title": "Text"
}
},
"type": "object",
"required":
[
"number",
"text"
],
"title": "Dummy"
},
"HTTPValidationError":
{
"properties":
{
"detail":
{
"items":
{
"$ref": "#/components/schemas/ValidationError"
},
"type": "array",
"title": "Detail"
}
},
"type": "object",
"title": "HTTPValidationError"
},
"OneBodyParam":
{
"properties":
{
"body_param":
{
"type": "string",
"title": "Body Param"
}
},
"type": "object",
"required":
[
"body_param"
],
"title": "OneBodyParam"
},
"TwoBodyParams":
{
"properties":
{
"body_param_1":
{
"type": "string",
"title": "Body Param 1"
},
"body_param_2":
{
"type": "string",
"title": "Body Param 2"
}
},
"type": "object",
"required":
[
"body_param_1",
"body_param_2"
],
"title": "TwoBodyParams"
},
"ValidationError":
{
"properties":
{
"loc":
{
"items":
{
"anyOf":
[
{
"type": "string"
},
{
"type": "integer"
}
]
},
"type": "array",
"title": "Location"
},
"msg":
{
"type": "string",
"title": "Message"
},
"type":
{
"type": "string",
"title": "Error Type"
}
},
"type": "object",
"required":
[
"loc",
"msg",
"type"
],
"title": "ValidationError"
}
}
}
} |
|
pydantic 2.11.0 broke it in quite a lot of places, this is only one of them Here is the relevant change to pydantic - pydantic/pydantic#11032, it's in the "spacebar heating" stage. You'll have to nail pydantic to <2.11.0 for now |
pydantic.warnings.PydanticDeprecatedSince211: Accessing the 'model_fields' attribute on the instance is deprecated. Instead, you should access this attribute from the model class. Deprecated in Pydantic V2.11 to be removed in V3.0.
|
While I'd prefer pydantic taking responsibility for this regression, let's roll with this for now. Thanks for notice. |
|
0.8.1 resolves this. |
Pydantic v2 treats 'model_config' as a reserved name for configuration. This caused runtime errors during dynamic model creation. Renamed the field to maintain compatibility.