cthoyt / zenodo-client

A tool for automated uploading and version management of scientific data to Zenodo
MIT License
25 stars 5 forks source link

"Field required" error on optional fields with `pydantic 2.6` #32

Closed rhigman closed 5 months ago

rhigman commented 6 months ago

I'm encountering the same error as described in #19 and previously fixed:

>>> creator = Creator(
...             name='Hoyt, Charles Tapley',
...             affiliation='Harvard Medical School',
...             orcid='0000-0003-4423-4370',
...         )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rh/.local/lib/python3.10/site-packages/pydantic/main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Creator
gnd
  Field required [type=missing, input_value={'name': 'Hoyt, Charles T...: '0000-0003-4423-4370'}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.6/v/missing

As previously noted, a workaround is to set the optional field to None:

>>> creator = Creator(
...             name='Hoyt, Charles Tapley',
...             orcid='0000-0003-4423-4370',
...             affiliation='Harvard Medical School',
...             gnd=None)
>>> creator
Creator(name='Hoyt, Charles Tapley', affiliation='Harvard Medical School', orcid='0000-0003-4423-4370', gnd=None)

I'm on pydantic==2.6.3 and pydantic_core==2.16.3.

rhigman commented 6 months ago

Bother, sorry, hadn't realised the fix to #19 isn't yet released. I was running on tag 0.3.2.

cthoyt commented 5 months ago

hi @rhigman, I finally made a new release after fixing some other unrelated issues. Can you check that v0.3.3 fixes your problem?

rhigman commented 5 months ago

Yes, fixed, thanks!