full-stack-fastapi-template icon indicating copy to clipboard operation
full-stack-fastapi-template copied to clipboard

Backend not starting: ImportError: cannot import name 'EmailStr' from 'pydantic.types'

Open merowinger92 opened this issue 6 years ago • 6 comments

The backend is not starting due to an import error:

backend_1        | INFO: Stopping reloader process [1]
backend_1        | Checking for script in /app/prestart.sh
backend_1        | Running script /app/prestart.sh
backend_1        | INFO:__main__:Initializing service
backend_1        | INFO:__main__:Starting call to '__main__.init', this is the 1st time calling it.
backend_1        | INFO:__main__:Service finished initializing
backend_1        | INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
backend_1        | INFO  [alembic.runtime.migration] Will assume transactional DDL.
backend_1        | INFO:__main__:Creating initial data
backend_1        | INFO:__main__:Initial data created
backend_1        | INFO: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
backend_1        | INFO: Started reloader process [1]
backend_1        | Process SpawnProcess-1:
backend_1        | Traceback (most recent call last):
backend_1        |   File "/usr/local/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
backend_1        |     self.run()
backend_1        |   File "/usr/local/lib/python3.7/multiprocessing/process.py", line 99, in run
backend_1        |     self._target(*self._args, **self._kwargs)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/supervisors/statreload.py", line 29, in handle_fds
backend_1        |     target(**kwargs)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/main.py", line 307, in run
backend_1        |     loop.run_until_complete(self.serve(sockets=sockets))
backend_1        |   File "uvloop/loop.pyx", line 1417, in uvloop.loop.Loop.run_until_complete
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/main.py", line 314, in serve
backend_1        |     config.load()
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/config.py", line 186, in load
backend_1        |     self.loaded_app = import_from_string(self.app)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/importer.py", line 23, in import_from_string
backend_1        |     raise exc from None
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/importer.py", line 20, in import_from_string
backend_1        |     module = importlib.import_module(module_str)
backend_1        |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
backend_1        |     return _bootstrap._gcd_import(name[level:], package, level)
backend_1        |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
backend_1        |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
backend_1        |   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
backend_1        |   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
backend_1        |   File "<frozen importlib._bootstrap_external>", line 728, in exec_module
backend_1        |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
backend_1        |   File "./app/main.py", line 5, in <module>
backend_1        |     from app.api.api_v1.api import api_router
backend_1        |   File "./app/api/api_v1/api.py", line 3, in <module>
backend_1        |     from app.api.api_v1.endpoints import items, login, users, utils
backend_1        |   File "./app/api/api_v1/endpoints/users.py", line 5, in <module>
backend_1        |     from pydantic.types import EmailStr
backend_1        | ImportError: cannot import name 'EmailStr' from 'pydantic.types' (/usr/local/lib/python3.7/site-packages/pydantic/types.cpython-37m-x86_64-linux-gnu.so)
backend_1        | INFO: Stopping reloader process [1]

I think this is because of the change in pydantic package that EmailStr was moved from pydantic.types to pydantic.networks (see this commit: Link

merowinger92 avatar Dec 04 '19 18:12 merowinger92

@merowinger92 this is an issue in pydantic 1.0.0 too right? Just want to make sure there wasn’t a breaking change from 1.1 to 1.2

dmontagu avatar Dec 04 '19 22:12 dmontagu

@dmontagu Yes, the networks.py file came in version v1.0b1

merowinger92 avatar Dec 05 '19 06:12 merowinger92

my 2 cents - the issue is still open.

madkote avatar Dec 17 '19 10:12 madkote

the simple fix is to edit:

  • backend/backend.dockerfile
  • backend/celeryworker.dockerfile

change the requirement to fastapi==0.41.*

madkote avatar Dec 17 '19 11:12 madkote

Thanks for the discussion here!

This was fixed in a PR and is now in master.

Could you confirm? May we close this issue @merowinger92 ?

tiangolo avatar Apr 13 '20 05:04 tiangolo

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

github-actions[bot] avatar Apr 24 '20 00:04 github-actions[bot]