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

FastAPI Users/ormar integration #91

Closed
paolodina opened this issue Jan 30, 2021 · 4 comments
Closed

FastAPI Users/ormar integration #91

paolodina opened this issue Jan 30, 2021 · 4 comments

Comments

@paolodina
Copy link

paolodina commented Jan 30, 2021

Reference: #84 (comment)

If you feel like it you can try on your own with FastapiUsers, I can help if you get stuck on the way :)

Yep, I'd be interested in doing that and thought to open this ticket to avoid that you or someone else also work on this at the same time.

I had a look at FastAPI Users code and I have to say that ormar/fastapi users integration shouldn't be too hard.
Basically they have the concept of "adapter", and the code for already implemented adapters is available here. Being able to provide the ormar adapter should do the trick, and for that I can take the Tortoise adapter as a starting point.

I hope to be able to finish the integration without issues and I'll keep this ticket updated when something will happen, in case of problems I accept your offer to help. I'll anyway refer to you @collerek for proofreading.

Thanks!

@collerek
Copy link
Owner

I looked quite some time ago into the fastapiusers and one trick point might be that it uses some template pydantic models to parse db models (at least that's what I remember, might have changed).

The trick is that ormar models are pydantic models so maybe you can skip the whole parsing in users but didn't dig deeper so hard to tell if this is really possible.

@paolodina
Copy link
Author

paolodina commented Jan 31, 2021

Ok, I got something.

There is the FastAPI Users fork (branch, commit) and here a the demo anyone can try and report back in case of problems.

Currently I tested only the /auth and /users endpoints, they seem working so far. I still have to test other endpoints and implement the oauth user case. I have some mypy errors in vscode too.

I'd appreciate if you could have a look at the code on the fork (basically it's only one file containing the implementation), it's commented with some question/consideration.

About this

The trick is that ormar models are pydantic models so maybe you can skip the whole parsing in users but didn't dig deeper so hard to tell if this is really possible.

I don't know if my code is OK but I didn't find any tricky part.

@collerek
Copy link
Owner

collerek commented Feb 2, 2021

Created a pull request paolodina/fastapi-users#1 with finished ormar db backend, with all power features of ormar used :)

Please review this and let me know what you think.
In my opinion what is left is more tests and documentation update but again didn't dig deep into fastapi-users and never used it.

As for the "tricky" part my idea was that maybe you can skip parsing to dict and recreating fastapi-users models but i think its impossible if the database have to return the fu users.

Run black and flake8 on the code but didn't run mypy, so it's also to be checked (if fastapi-users uses it).

@collerek
Copy link
Owner

collerek commented Feb 7, 2021

@paolodina the PR is merged!
Good job and thanks ;)

If you have other fastapi ecosystem libraries that you would like ormar to support let me know, we can work this out ;)

@collerek collerek closed this as completed Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants