question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to import: `Field` default cannot be set in `Annotated` for 'num_Annotated[str, FieldInfo(min_length=1, extra={})]'

See original GitHub issue

Error message:

Traceback (most recent call last):
  File "/data/cuih7/[REDACTED]", line 7, in <module>
    import inflect
  File "/data/cuih7/miniconda3/envs/nlp20220817/lib/python3.10/site-packages/inflect/__init__.py", line 2046, in <module>
    class engine:
  File "/data/cuih7/miniconda3/envs/nlp20220817/lib/python3.10/site-packages/inflect/__init__.py", line 3781, in engine
    def number_to_words(  # noqa: C901
  File "pydantic/decorator.py", line 36, in pydantic.decorator.validate_arguments.validate
    import sys
  File "pydantic/decorator.py", line 126, in pydantic.decorator.ValidatedFunction.__init__
    try:
  File "pydantic/decorator.py", line 259, in pydantic.decorator.ValidatedFunction.create_model
    return fun
  File "pydantic/main.py", line 972, in pydantic.main.create_model
  File "pydantic/main.py", line 204, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 534, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 633, in pydantic.fields.ModelField._type_analysis
  File "pydantic/fields.py", line 776, in pydantic.fields.ModelField._create_sub_type
  File "pydantic/fields.py", line 451, in pydantic.fields.ModelField._get_field_info
ValueError: `Field` default cannot be set in `Annotated` for 'num_Annotated[str, FieldInfo(min_length=1, extra={})]'

I’m using the library from conda-forge. Downgrading from 6.0.0-pyhd8ed1ab_0 to 5.6.2-pyhd8ed1ab_0 fixes the issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
akpekercommented, Oct 20, 2022

Thanks, I think the issue is mostly clarified. Either need to update pydantic to above 1.9 (maybe below 1.9 works too?) or downgrade inflect to e.g. 5.6. I use conda and unfortunately it let’s me update only to pydantic 1.9, but let’s me downgrade inflect to 5.3, and everything seems to work fine then. Good enough for me.

1reaction
jaracocommented, Oct 20, 2022

In fact, tests pass on pydantic 1.9.1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: `Field` default cannot be set in `Annotated` for ...
Failed to import: Field default cannot be set in Annotated for 'num_Annotated[str, FieldInfo(min_length=1, extra={})]' jaraco/inflect#169.
Read more >
pydantic setting a default value for an annotated type
I've been running into an issue where I am trying to set a default value. The basic idea is that there is a...
Read more >
Pydantic only fields - ormar
If ormar cannot resolve the value for pydantic field it will fail during ... If you set a field as Optional , it...
Read more >
Postponed annotations - pydantic
Both postponed annotations via the future import and ForwardRef require Python 3.7+. Postponed annotations (as described in PEP563) "just work".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found