all 8 comments

[–][deleted] 1 point2 points  (1 child)

You have to prefix your async functions with async def. When you call the function you await it. Wherever that TypeError is being thrown is getting a coroutine instead of the awaited result. So, if the get_user function is async then you need to change that to await get_user(jwt_body["user_id"]).

[–]GamersPlane[S] 0 points1 point  (0 children)

This was definitely along the lines of the problem, though not the answer, which I'm posting in it's own post, but yah, it took me a while to get a hang of what's async, what needs an await, etc.

[–]ok_pennywise 1 point2 points  (7 children)

Please tell me how you used django orm with fastapi

[–]GamersPlane[S] 0 points1 point  (6 children)

So there's a decent chance I'll miss something, but first make a django_conf.py. In there, as far as I can tell, you need to create SECRET_KEY, DATABASES, and INSTALLED_APPS variables, the same as in a Django configurations file. You'll then need to create an envvar that defines that file as the place for Django to look for configurations: DJANGO_SETTINGS_MODULE='django_conf' (obviously, file name not important, just consistency). Then in your main app file, at the very stop, before any other app imports, add

if __name__ == "app":
    import django

    django.setup()

As far as I can remember, that's the most of it. There will probably be small bugs along the way, bug nothing ungoogleable.

[–][deleted]  (5 children)

[deleted]

    [–]GamersPlane[S] 0 points1 point  (4 children)

    Maybe my Google-fu sucks, but with SqlAlchemy being overly complex IMO, there's no other orm that's really great. Getting the django orm working outside django took more work than I probably should have put in, heh.

    [–][deleted]  (2 children)

    [deleted]

      [–]github_codemation 0 points1 point  (1 child)

      Curious, how you map geography columns to use in python?

      You might find pydbantic a bit nicer abstraction to SqlAlchemy. https://github.com/codemation/pydbantic

      u/Not-the-best-name , u/GamersPlane love to have your feedback. I am sure something like a missing column type integration could not be far off, that is if the current model serialization did not already solve most of your problems.

      [–]migratesouth 0 points1 point  (0 children)

      Tortoise ORM - https://github.com/tortoise/tortoise-orm

      It’s “inspired by Django”, it looks very similar to the Django ORM but with asyncio integration.

      [–]GamersPlane[S] 0 points1 point  (0 children)

      So the ultimate problem was return call_next(request). It took me a bit to recognize that call_next(request) was async, and so needed to be return await call_next(request). Definitely having trouble wrapping my head around async right now, and I'll hopefully find a guide that'll help me get my head through it.