Bug
I think #1422 causes an unintentional (?) change in the behaviour of __modify_schema__ - it's now applying to the list schema as well as the item schema.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.5.1
pydantic compiled: False
install path: /home/johnc/Projects/pydantic/pydantic
python version: 3.7.7 (default, Apr 18 2020, 02:59:53) [GCC 9.3.0]
platform: Linux-5.4.0-29-generic-x86_64-with-Ubuntu-20.04-focal
optional deps. installed: []
Actually at git version 5195e55 -
pip freeze | grep pydantic
-e git+https://github.com/samuelcolvin/pydantic.git@5195e55c102e537be6c00579df8f464ecd90b5ff#egg=pydantic
The output of the following code is different between master and v1.5.1
from typing import List
import pydantic
class MyField(str):
@classmethod
def __modify_schema__(cls, field_schema):
field_schema["foo"] = "buzz"
class Foo(pydantic.BaseModel):
a_field: MyField
some_fields: List[MyField]
print(Foo.schema_json(indent=2))
With 1.5.1 this outputs:
{
"title": "Foo",
"type": "object",
"properties": {
"a_field": {
"title": "A Field",
"type": "string",
"foo": "buzz"
},
"some_fields": {
"title": "Some Fields",
"type": "array",
"items": {
"type": "string",
"foo": "buzz"
}
}
},
"required": [
"a_field",
"some_fields"
]
}
With current master this outputs:
{
"title": "Foo",
"type": "object",
"properties": {
"a_field": {
"title": "A Field",
"foo": "buzz",
"type": "string"
},
"some_fields": {
"title": "Some Fields",
"foo": "buzz",
"type": "array",
"items": {
"type": "string",
"foo": "buzz"
}
}
},
"required": [
"a_field",
"some_fields"
]
}
Diff:
{
"title": "Foo",
"type": "object",
"properties": {
"a_field": {
"title": "A Field",
- "type": "string",
- "foo": "buzz"
+ "foo": "buzz",
+ "type": "string"
},
"some_fields": {
"title": "Some Fields",
+ "foo": "buzz",
"type": "array",
"items": {
"type": "string",
"foo": "buzz"
}
}
},
"required": [
"a_field",
"some_fields"
]
}
Note the extra "foo" in some_fields - I think this is a regression?
Bug
I think #1422 causes an unintentional (?) change in the behaviour of
__modify_schema__- it's now applying to the list schema as well as the item schema.Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())":Actually at git version 5195e55 -
The output of the following code is different between master and v1.5.1
With 1.5.1 this outputs:
With current master this outputs:
Diff:
{ "title": "Foo", "type": "object", "properties": { "a_field": { "title": "A Field", - "type": "string", - "foo": "buzz" + "foo": "buzz", + "type": "string" }, "some_fields": { "title": "Some Fields", + "foo": "buzz", "type": "array", "items": { "type": "string", "foo": "buzz" } } }, "required": [ "a_field", "some_fields" ] }Note the extra "foo" in
some_fields- I think this is a regression?