TypeError: cannot specify both default and default_factory

Hello, the program that used to work fine suddenly stopped working, and so far I haven’t been able to resolve it. I reinstalled the mp-api library and pydantic, but it still doesn’t work.I am seeking help. I would greatly appreciate it if you could help me solve these problems.


Traceback (most recent call last):
File “E:\python\cursor23\1.py”, line 10, in
docs = mpr.materials.summary.search(elements=[‘Li’])
File “D:\anaconda3\Lib\site-packages\mp_api\client\routes\materials\summary.py”, line 367, in search
return super()._search(
~~~~~~~~~~~~~~~^
num_chunks=num_chunks,
^^^^^^^^^^^^^^^^^^^^^^
…<3 lines>…
**query_params,
^^^^^^^^^^^^^^^
)
^
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 1207, in _search
return self._get_all_documents(
~~~~~~~~~~~~~~~~~~~~~~~^
kwargs,
^^^^^^^
…<3 lines>…
num_chunks=num_chunks,
^^^^^^^^^^^^^^^^^^^^^^
)
^
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 1286, in _get_all_documents
results = self._query_resource(
query_params,
…<3 lines>…
num_chunks=num_chunks,
)
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 564, in _query_resource
data = self._submit_requests(
url=url,
…<5 lines>…
timeout=timeout,
)
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 711, in _submit_requests
initial_data_tuples = self._multi_thread(
self._submit_request_and_process, initial_params_list
)
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 933, in _multi_thread
data, subtotal = future.result()
~~~~~~~~~~~~~^^
File “D:\anaconda3\Lib\concurrent\futures_base.py”, line 449, in result
return self.__get_result()
~~~~~~~~~~~~~~~~~^^
File “D:\anaconda3\Lib\concurrent\futures_base.py”, line 401, in __get_result
raise self._exception
File “D:\anaconda3\Lib\concurrent\futures\thread.py”, line 59, in run
result = self.fn(*self.args, **self.kwargs)
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 1007, in _submit_request_and_process
data[“data”] = self._convert_to_model(data[“data”])
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 1044, in _convert_to_model
data_model, set_fields, _ = self._generate_returned_model(data[0])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File “D:\anaconda3\Lib\site-packages\mp_api\client\core\client.py”, line 1086, in generate_returned_model
data_model = create_model( # type: ignore
“MPDataDoc”,
…<10 lines>…
module=self.document_model.module,
)
File “D:\anaconda3\Lib\site-packages\pydantic\main.py”, line 1804, in create_model
return meta(
model_name,
…<4 lines>…
**kwds,
)
File “D:\anaconda3\Lib\site-packages\pydantic_internal_model_construction.py”, line 242, in new
set_model_fields(cls, config_wrapper=config_wrapper, ns_resolver=ns_resolver)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\anaconda3\Lib\site-packages\pydantic_internal_model_construction.py”, line 566, in set_model_fields
fields, class_vars = collect_model_fields(cls, config_wrapper, ns_resolver, typevars_map=typevars_map)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\anaconda3\Lib\site-packages\pydantic_internal_fields.py”, line 363, in collect_model_fields
field_info = FieldInfo
.from_annotated_attribute(ann_type, assigned_value, _source=AnnotationSource.CLASS)
File “D:\anaconda3\Lib\site-packages\pydantic\fields.py”, line 468, in from_annotated_attribute
field_info = FieldInfo._construct(
prepend_metadata + metadata if prepend_metadata is not None else metadata, **attr_overrides
)
File “D:\anaconda3\Lib\site-packages\pydantic\fields.py”, line 563, in _construct
merged_field_info = cls(**merged_kwargs)
File “D:\anaconda3\Lib\site-packages\pydantic\fields.py”, line 252, in init
raise TypeError(‘cannot specify both default and default_factory’)
TypeError: cannot specify both default and default_factory

Hi this is a bug we fixed last Friday; you can either install the pre-release which includes the fix using pip install mp_api==0.45.13rc3, or downgrade pip install pydantic==2.12.2. The latter will probably be more stable as we’re working through compatibility with pydantic

Hi, It’s working now. thank you for your guidance.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.