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

Bug: string Infinity transformed to inf float when transforming to Pydantic model, which makes starlette to crash #948

Closed
JoanFM opened this issue Dec 15, 2022 · 0 comments · Fixed by #949

Comments

@JoanFM
Copy link
Member

JoanFM commented Dec 15, 2022

Describe the bug

from jina import Document

d = Document()
d.tags['title'] = 'Infinity'

print(d.to_dict())

print(float('Infinity'))

this shows that it transforms to inf which makes starlette fail with:

Traceback (most recent call last):
  File "/home/joan/.local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 371, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/joan/.local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 59, in __call__
    return await self.app(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/fastapi/applications.py", line 270, in __call__
    await super().__call__(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/middleware/cors.py", line 84, in __call__
    await self.app(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/joan/.local/lib/python3.7/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/joan/.local/lib/python3.7/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/home/joan/.local/lib/python3.7/site-packages/fastapi/routing.py", line 264, in app
    response = actual_response_class(content, **response_args)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/responses.py", line 192, in __init__
    super().__init__(content, status_code, headers, media_type, background)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/responses.py", line 54, in __init__
    self.body = self.render(content)
  File "/home/joan/.local/lib/python3.7/site-packages/starlette/responses.py", line 200, in render
    separators=(",", ":"),
  File "/usr/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
ValueError: Out of range float values are not JSON compliant

I believe it may be related to:

pydantic/pydantic#1417

@JohannesMessner JohannesMessner linked a pull request Dec 16, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant