You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below crashes with the following traceback. See also #8897, which was closed.
Traceback (most recent call last):
File "/home/joerg/tmp/pydantic_key_error.py", line 22, in <module>
class Model4(BaseModel, frozen=True):
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 202, in __new__
complete_model_class(
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 549, in complete_model_class
schema = gen_schema.clean_schema(schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 435, in clean_schema
schema = simplify_schema_references(schema)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 463, in simplify_schema_references
schema = walk_core_schema(schema, count_refs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 414, in walk_core_schema
return f(schema.copy(), _dispatch)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 459, in count_refs
recurse(definitions[ref], count_refs)
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 197, in walk
return f(schema, self._walk)
^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 447, in count_refs
return recurse(s, count_refs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 200, in _walk
schema = self._schema_type_to_method[schema['type']](schema.copy(), f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 209, in _handle_other_schemas
schema['schema'] = self.walk(sub_schema, f) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 197, in walk
return f(schema, self._walk)
^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 447, in count_refs
return recurse(s, count_refs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 200, in _walk
schema = self._schema_type_to_method[schema['type']](schema.copy(), f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 337, in handle_model_fields_schema
replaced_field['schema'] = self.walk(v['schema'], f)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 197, in walk
return f(schema, self._walk)
^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 459, in count_refs
recurse(definitions[ref], count_refs)
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 200, in _walk
schema = self._schema_type_to_method[schema['type']](schema.copy(), f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 209, in _handle_other_schemas
schema['schema'] = self.walk(sub_schema, f) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 197, in walk
return f(schema, self._walk)
^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 447, in count_refs
return recurse(s, count_refs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 200, in _walk
schema = self._schema_type_to_method[schema['type']](schema.copy(), f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 337, in handle_model_fields_schema
replaced_field['schema'] = self.walk(v['schema'], f)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 197, in walk
return f(schema, self._walk)
^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 447, in count_refs
return recurse(s, count_refs)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 203, in _walk
schema['serialization'] = self._handle_ser_schemas(ser_schema, f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 215, in _handle_ser_schemas
ser_schema['schema'] = self.walk(schema, f) # type: ignore
^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 197, in walk
return f(schema, self._walk)
^^^^^^^^^^^^^^^^^^^^^
File "/home/joerg/.pyenv/versions/3.12.1/lib/python3.12/site-packages/pydantic/_internal/_core_utils.py", line 459, in count_refs
recurse(definitions[ref], count_refs)
~~~~~~~~~~~^^^^^
KeyError: '__main__.Model1:110296424761552'
Initial Checks
Description
The code below crashes with the following traceback. See also #8897, which was closed.
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: