litestar-org / litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
https://litestar.dev/
MIT License
5.52k stars 378 forks source link

Bug:AttributeError: module 'pydantic._migration' has no attribute 'JsonValue' #3391

Closed kodecreer closed 6 months ago

kodecreer commented 6 months ago

Description

It pulls up this error when following the tutorial. This appears to be something caused by pydantic migrations for some reason?

Here is my dependancies annotated-types==0.6.0 anyio==4.3.0 certifi==2024.2.2 click==8.1.7 EditorConfig==0.12.4 exceptiongroup==1.2.0 Faker==24.9.0 fast-query-parsers==1.0.3 h11==0.14.0 httpcore==1.0.5 httptools==0.6.1 httpx==0.27.0 idna==3.7 Jinja2==3.1.3 jsbeautifier==1.15.1 litestar==2.8.2 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 msgspec==0.18.6 multidict==6.0.5 polyfactory==2.15.0 pydantic==2.7.0 pydantic_core==2.18.1 Pygments==2.17.2 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 PyYAML==6.0.1 rich==13.7.1 rich-click==1.7.4 six==1.16.0 sniffio==1.3.1 typing_extensions==4.11.0 uvicorn==0.29.0 uvloop==0.19.0 watchfiles==0.21.0 websockets==12.0

URL to code causing the issue

No response

MCVE

# Your MCVE code here

Steps to reproduce

1. Enter Hello world tutorial online 
2. Use litestar run

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/uvicorn", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/main.py", line 409, in main
    run(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/main.py", line 575, in run
    server.run()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/server.py", line 69, in serve
    await self._serve(sockets)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/server.py", line 76, in _serve
    config.load()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/config.py", line 433, in load
    self.loaded_app = import_from_string(self.app)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/uvicorn/importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/kodecreer/Documents/Python/Litestar/app.py", line 8, in <module>
    app = Litestar([hello_world])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/litestar/app.py", line 361, in __init__
    plugins=self._get_default_plugins(list(plugins or [])),
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/litestar/app.py", line 521, in _get_default_plugins
    from litestar.contrib.pydantic import (
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/litestar/contrib/pydantic/__init__.py", line 8, in <module>
    from .pydantic_dto_factory import PydanticDTO
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/litestar/contrib/pydantic/pydantic_dto_factory.py", line 62, in <module>
    pydantic_v2.JsonValue: Any,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pydantic/__init__.py", line 210, in __getattr__
    return _getattr_migration(attr_name)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pydantic/_migration.py", line 299, in wrapper
    raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
AttributeError: module 'pydantic._migration' has no attribute 'JsonValue'

Litestar Version

2.82

Platform


[!NOTE]
While we are open for sponsoring on GitHub Sponsors and OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.

Fund with Polar

provinzkraut commented 6 months ago

Hi @kodecreer, thanks for reporting!

I cannot reproduce this as of now with the dependencies you specified on Python 3.10. That being said though, I have only tested it on Linux, but I don't think that would make a difference :eyeglasses:

Just to confirm, this is the code you're running?

from litestar import Litestar, get

@get("/")
async def hello_world() -> str:
    return "Hello, world!"

app = Litestar([hello_world])
kodecreer commented 6 months ago

Yes that's the exact code I ran. Python version is 3.10.5

kodecreer commented 6 months ago

Ok found out the issue. Litestar for some reason doesn't work with Python version 3.10.5 on Mac. It's reccomended to use a different version of python . I am here if you prefer to continue investigating the cause of this issue. I updated my python version to 3.12 and it worked fine.

provinzkraut commented 6 months ago

It's reccomended to use a different version of python

Recommended by whom? :eyes:

Is this some dependency resolution thing? If yes, how have you installed Litestar?

kodecreer commented 6 months ago

By me because it fixed my issue on my Mac and in case someone runs into the same issue in the future.

Probably something in the implmentation of Python on Mac. Forgot to mention it's monterey OSX I installed it using "pip install litestar[standard]"