Skip to content

Weak support for 'ForwardRef' with python 3.6.8 #8

@ebreton

Description

@ebreton
Contributor

Hi @tiangolo ,

Thanks a lot for your amazing contributions. fastapi 🎈 . dockerswarmrocks 🌟 , and all projects generators 🚀

I just hit an issue when creating my first one-to-many relationship, as described in fastapi/fastapi#153.

One straightforward solution is to move up the python version from 3.6 to 3.7 in the Dockerfile(s).

So you have any particular advices to do this ? or shall I just create a PR with the 3 corrections ?

Emmanuel
-- cortexia.ch

Activity

ebreton

ebreton commented on Apr 13, 2019

@ebreton
ContributorAuthor

Some feedback on trying out 3.7 :

  • 👌 fixes correctly forwardRef, and allows cross references (as needed in the initial use-case of a one-to-many relationship)
  • 💣 breaks celery test (traceback below), which is connected to celery beat bug with python 3.7 re pattern_type change celery/celery#5416, with following conclusion:

    celery 4.2.x doesn't support python 3.7, please try celery 4.3rc3 to get rid of the bug and report if you found any other bug in celery 4.3rc3 :)

  • 👍 when changing celery version in Pipfile and Dockerfiles from "==4.2.1" to "~=4.3"

I will create a pull request with the results, and link back to this issue

traceback in tests:

=================================== FAILURES ===================================
___________________________ test_celery_worker_test ____________________________

superuser_token_headers = {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE1NTU4MzMyNTIsInN1YiI6ImFjY2VzcyJ9.MA2lR8rBh7gBst5ZCKJmKQAdu2qnLwYIypu5o3zNjfg'}

    def test_celery_worker_test(superuser_token_headers):
        server_api = get_server_api()
        data = {"msg": "test"}
        r = requests.post(
            f"{server_api}{config.API_V1_STR}/test-celery/",
            json=data,
            headers=superuser_token_headers,
        )
>       response = r.json()

app/app/tests/api/api_v1/test_celery.py:15:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
usr/local/lib/python3.7/site-packages/requests/models.py:897: in json
    return complexjson.loads(self.text, **kwargs)
usr/local/lib/python3.7/json/__init__.py:348: in loads
    return _default_decoder.decode(s)
usr/local/lib/python3.7/json/decoder.py:337: in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <json.decoder.JSONDecoder object at 0x7fc370c3a0f0>
s = 'Internal Server Error', idx = 0

    def raw_decode(self, s, idx=0):
        """Decode a JSON document from ``s`` (a ``str`` beginning with
        a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration as err:
>           raise JSONDecodeError("Expecting value", s, err.value) from None
E           json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

usr/local/lib/python3.7/json/decoder.py:355: JSONDecodeError
===================== 1 failed, 16 passed in 6.42 seconds ======================

traceback in application:

backend_1        | [2019-04-13 07:26:27 +0000] [13] [ERROR] Exception in ASGI application
backend_1        | Traceback (most recent call last):
backend_1        |   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 372, in run_asgi
backend_1        |     result = await asgi(self.receive, self.send)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 125, in asgi
backend_1        |     raise exc from None
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 103, in asgi
backend_1        |     await asgi(receive, _send)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/base.py", line 27, in asgi
backend_1        |     response = await self.dispatch_func(request, self.call_next)
backend_1        |   File "/app/app/main.py", line 34, in db_session_middleware
backend_1        |     response = await call_next(request)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/base.py", line 44, in call_next
backend_1        |     task.result()
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/base.py", line 37, in coro
backend_1        |     await inner(request.receive, queue.put)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/exceptions.py", line 74, in app
backend_1        |     raise exc from None
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/exceptions.py", line 63, in app
backend_1        |     await instance(receive, sender)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 41, in awaitable
backend_1        |     response = await func(request)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/fastapi/routing.py", line 84, in app
backend_1        |     raw_response = await run_in_threadpool(dependant.call, **values)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/starlette/concurrency.py", line 24, in run_in_threadpool
backend_1        |     return await loop.run_in_executor(None, func, *args)
backend_1        |   File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
backend_1        |     result = self.fn(*self.args, **self.kwargs)
backend_1        |   File "/app/app/api/api_v1/endpoints/utils.py", line 20, in test_celery
backend_1        |     celery_app.send_task("app.worker.test_celery", args=[msg.msg])
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/base.py", line 708, in send_task
backend_1        |     router = router or amqp.router
backend_1        |   File "/usr/local/lib/python3.7/site-packages/kombu/utils/objects.py", line 44, in __get__
backend_1        |     value = obj.__dict__[self.__name__] = self.__get(obj)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/amqp.py", line 606, in router
backend_1        |     return self.Router()
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/amqp.py", line 284, in Router
backend_1        |     return _routes.Router(self.routes, queues or self.queues,
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/amqp.py", line 601, in routes
backend_1        |     self.flush_routes()
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/amqp.py", line 289, in flush_routes
backend_1        |     self._rtable = _routes.prepare(self.app.conf.task_routes)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/routes.py", line 136, in prepare
backend_1        |     return [expand_route(route) for route in routes]
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/routes.py", line 136, in <listcomp>
backend_1        |     return [expand_route(route) for route in routes]
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/routes.py", line 127, in expand_route
backend_1        |     return MapRoute(route)
backend_1        |   File "/usr/local/lib/python3.7/site-packages/celery/app/routes.py", line 36, in __init__
backend_1        |     if isinstance(k, re._pattern_type):
backend_1        | AttributeError: module 're' has no attribute '_pattern_type'
euri10

euri10 commented on Apr 13, 2019

@euri10
tiangolo

tiangolo commented on Apr 16, 2019

@tiangolo
Member

Good job @ebreton !

That's right @euri10 , it was because of Celery and TensorFlow.

But now Celery and TensorFlow both support Python 3.7 🎉

ebreton

ebreton commented on Apr 23, 2019

@ebreton
ContributorAuthor

Fixed with PR #10

tiangolo

tiangolo commented on Apr 27, 2019

@tiangolo
Member

Thanks for reporting back and closing the issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ebreton@euri10@tiangolo

        Issue actions

          Weak support for 'ForwardRef' with python 3.6.8 · Issue #8 · fastapi/full-stack-fastapi-template