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.

Feature request: ForwardRef support for dataclasses

See original GitHub issue

Bug

With python 3.7+ from __future__ import annotations the example is broken and raises an exception.

  • OS: OS X 10.13.6 (17G4015)
  • Python version: 3.7.1
  • Pydantic version: 0.19
# only the following line was changed compared to the example
# in the docs https://pydantic-docs.helpmanual.io/#nested-dataclasses
from __future__ import annotations 

from pydantic import UrlStr
from pydantic.dataclasses import dataclass

@dataclass
class NavbarButton:
    href: UrlStr

@dataclass
class Navbar:
    button: NavbarButton

navbar = Navbar(button=('https://example.com',))
print(navbar)
 python foo.py
Traceback (most recent call last):
  File "foo.py", line 13, in <module>
    navbar = Navbar(button=('https://example.com',))
  File "<string>", line 3, in __init__
  File "/tmp/env/lib/python3.7/site-packages/pydantic/dataclasses.py", line 25, in _pydantic_post_init
    d = validate_model(self.__pydantic_model__, self.__dict__)
  File "/tmp/env/lib/python3.7/site-packages/pydantic/main.py", line 508, in validate_model
    f"field {field.name} not yet prepared and type is still a ForwardRef, "
pydantic.errors.ConfigError: field button not yet prepared and type is still a ForwardRef, you'll need to call MetaModel.update_forward_refs()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
samuelcolvincommented, Feb 17, 2019

should be fixed by #399, let me know if this fixes the issue for you.

1reaction
ceeliancommented, Feb 18, 2019

Ah, got it. Thank you for clarification and the fast implementation of the new feature!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: ForwardRef support for dataclasses #397
With python 3.7+ from __future__ import annotations the example is broken and raises an exception. OS: OS X 10.13.6 (17G4015); Python version: ...
Read more >
Issue 41370: PEP 585 and ForwardRef - Python tracker
I asked for a brief example that explains your issue to me. Instead you sent me links to production code and patches to...
Read more >
pydantic — pydantic v0.28 documentation
Both postponed annotations via the future import and ForwardRef require python 3.7+. Support for those features starts from pydantic v0.18. Postponed ...
Read more >
Changelog - pydantic
Refactor the whole pydantic dataclass decorator to really act like its standard ... Fix implicitly importing ForwardRef and Callable from pydantic.typing ...
Read more >
2.0 Changelog — SQLAlchemy 2.0 Documentation
Added support custom user-defined types which extend the Python enum. ... Fixed bug in Declarative Dataclass Mapping feature where using ...
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