Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctr api doc error on docker #847

Closed
dvivarelli opened this issue Mar 10, 2022 · 11 comments · Fixed by #997
Closed

Doctr api doc error on docker #847

dvivarelli opened this issue Mar 10, 2022 · 11 comments · Fixed by #997
Assignees
Labels
ext: api Related to api folder topic: docker Docker-related type: bug Something isn't working

Comments

@dvivarelli
Copy link

dvivarelli commented Mar 10, 2022

Bug description

I have cloned the project and build the image with docker compose and tried to open the documentation at http://localhost:8002/redoc but the page remains in loading.

I have checked the network tab on chrome and I saw an error:

GET http://localhost:8002/openapi.json

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 25, in __call__
    response = await self.dispatch_func(request, self.call_next)
  File "/app/./app/main.py", line 26, in add_process_time_header
    response = await call_next(request)
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 45, in call_next
    task.result()
  File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 38, in coro
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 161, in openapi
    return JSONResponse(self.openapi())
  File "/app/./app/main.py", line 36, in custom_openapi
    openapi_schema = get_openapi(
  File "/usr/local/lib/python3.8/site-packages/fastapi/openapi/utils.py", line 410, in get_openapi
    return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True)  # type: ignore
  File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 4 validation errors for OpenAPI
components -> schemas -> DetectionOut -> properties -> box -> items
  value is not a valid dict (type=type_error.dict)
components -> schemas -> DetectionOut -> $ref
  field required (type=value_error.missing)
components -> schemas -> OCROut -> properties -> box -> items
  value is not a valid dict (type=type_error.dict)
components -> schemas -> OCROut -> $ref
  field required (type=value_error.missing)

Code snippet to reproduce the bug

--

Error traceback

Traceback (most recent call last):
 File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
   await self.app(scope, receive, _send)
 File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 25, in __call__
   response = await self.dispatch_func(request, self.call_next)
 File "/app/./app/main.py", line 26, in add_process_time_header
   response = await call_next(request)
 File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 45, in call_next
   task.result()
 File "/usr/local/lib/python3.8/site-packages/starlette/middleware/base.py", line 38, in coro
   await self.app(scope, receive, send)
 File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
   raise exc from None
 File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
   await self.app(scope, receive, sender)
 File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
   await route.handle(scope, receive, send)

Environment

image built with docker compose

@dvivarelli dvivarelli added the type: bug Something isn't working label Mar 10, 2022
@fg-mindee fg-mindee self-assigned this Mar 10, 2022
@fg-mindee fg-mindee added the ext: api Related to api folder label Mar 10, 2022
@fg-mindee
Copy link
Contributor

Hi there @dvivarelli 👋

Thanks for reporting this! Let's try to tackle this:

  • I just tried with the latest version of the repo, and had no problem accessing the documentation. Did you follow the steps in https://github.com/mindee/doctr/tree/main/api/README.md ? (after pulling the latest version)
  • you didn't fill the code snippet used to produce this, would you mind editing this so that I can try to reproduce this please? 🙏
  • For the environment, there were some instructions to retrieve the useful details in the issue form. I understand you built it with docker, but still, depending on the OS and other environment details, the image built can vary (CPU architecture difference for instance). So would you mind running the following command and paste the console output here?
wget https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

Cheers ✌️

@fg-mindee fg-mindee added the awaiting response Waiting for feedback label Mar 10, 2022
@Ankush2k
Copy link

Ankush2k commented Apr 4, 2022

Hi @fg-mindee,

Process to replicate the issue as I faced this as well,

  1. cloning the repo-

Screenshot 2022-04-05 at 2 12 22 AM

  1. Using the command mentioned in above readme provided, PORT=8002
    Screenshot 2022-04-05 at 2 14 12 AM

  2. The container is up and running,
    Screenshot 2022-04-05 at 2 36 07 AM

  3. Trying the docs and redoc,
    http://localhost:8002/doc

Screenshot 2022-04-05 at 2 15 58 AM

and http://localhost:8002/redoc

Screenshot 2022-04-05 at 2 16 48 AM

If there is anything missed, can you please point that at certain step.

@fxfabre
Copy link

fxfabre commented Apr 5, 2022

I have the exact same error :

web_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi/openapi/utils.py", line 410, in get_openapi
web_1  |     return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True)  # type: ignore
web_1  |   File "pydantic/main.py", line 406, in pydantic.main.BaseModel.__init__
web_1  | pydantic.error_wrappers.ValidationError: 2 validation errors for OpenAPI
web_1  | components -> schemas -> OCROut -> properties -> box -> items
web_1  |   value is not a valid dict (type=type_error.dict)
web_1  | components -> schemas -> OCROut -> $ref
web_1  |   field required (type=value_error.missing)

I can remove the error, at least to display the openapi doc by :

  • removing response_model=List[DetectionOut] in routes/detection.py
  • removing response_model=List[OCROut] in routes/ocr.py

It is not a valid solution, just a hint to try to find a correct solution. Seems to be an issue with pydantic

I am running docker from Windows 11 / WSL 2 without cuda

$ uname -a
Linux 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of https://raw.githubusercontent.com/mindee/doctr/main/scripts/collect_env.py inside the container :

DocTR version: 0.6.0a0
TensorFlow version: 2.6.3
PyTorch version: N/A (torchvision N/A)
OpenCV version: 4.5.5
OS: Debian GNU/Linux 11 (bullseye)
Python version: 3.8.12
Is CUDA available (TensorFlow): No
Is CUDA available (PyTorch): N/A
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Extract of pip freeze :

fastapi==0.68.1
gunicorn==20.1.0
pydantic==1.8.2

@spielhoelle
Copy link

Same problem here: Failed to load API definition.

@Ankush2k
Copy link

Hi @fg-mindee,

I believe there is some issue in internal function call, because of that we are facing this issue.
For Doctr as an API on Docker, I have implemented a sample of my own.
reference,
https://github.com/Ankush2k/docTR-API-example.

But if this can be implemented in original Doctr repo with proper standards that will be helpful to all.

Thanks.

@charlesmindee
Copy link
Collaborator

Hi everyone, thanks for reporting that, I am able to reproduce the bug. I managed to get the docs with the "solution" of @fxfabre, we need to investigate that. Any idea @frgfm ?

@frgfm
Copy link
Collaborator

frgfm commented Apr 28, 2022

Hi everyone 👋

Considering the traceback (problems arise in the middleware), my suspicions are directed towards a new incompatible version of starlette or FastAPI. Let me run some checks, and I'll report the results back here 👍

@frgfm
Copy link
Collaborator

frgfm commented May 7, 2022

Quick update everyone!
So #906 shows that the problem is still ongoing on "main" branch and the CI will pick it. I checked changes in starlette & fastapi versions but the problem didn't come from there. I have some issues on my personal laptop with docker so the resolution is taking a bit longer than expected!

Will keep you updated 👍

@frgfm frgfm added topic: docker Docker-related and removed awaiting response Waiting for feedback labels May 7, 2022
@frgfm frgfm assigned frgfm and unassigned fg-mindee May 7, 2022
@SamSamhuns
Copy link

It seems to work for me once I update the fastapi version to fastapi>=0.78.0 from fastapi>=0.65.2 in doctr/api/requirements.txt

@frgfm
Copy link
Collaborator

frgfm commented Jun 1, 2022

It seems to work for me once I update the fastapi version to fastapi>=0.78.0 from fastapi>=0.65.2 in doctr/api/requirements.txt

I just managed to get my hands on a new setup so that I can run docker again easily, I'll check all of this by the end of next week! Thanks for reporting the fix @SamSamhuns :)

@odulcy-mindee
Copy link
Collaborator

@fxfabre @SamSamhuns Thank you for your hints! It seems related to a problem on FastAPi using nested pydantic models with Tuples (fastapi/fastapi#3782, fastapi/fastapi#4168) which we used in DetectionOut and OCROut (which depends on the former).

Updating fastapi should fix the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: api Related to api folder topic: docker Docker-related type: bug Something isn't working
Projects
None yet
9 participants