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

Remove fastapi-users-db-sqlmodel dependency #488

Closed
Tracked by #575
tcompa opened this issue Feb 3, 2023 · 8 comments
Closed
Tracked by #575

Remove fastapi-users-db-sqlmodel dependency #488

tcompa opened this issue Feb 3, 2023 · 8 comments

Comments

@tcompa
Copy link
Collaborator

tcompa commented Feb 3, 2023

Context: this question came up while working (with @mfranzon) on a pydantic/sqlmodel/sqlalchemy issue which is not yet clear. We don't know if the two issues are related, but in general this one here has to be considered at some point.

--

We depend on fastapi-users-db-sqlmodel, that currently (as of their 0.2.0 version) forces sqlalchemy version to be <=1.4.35. The reason is that 1.4.36 introduced a widespread issue, including in sqlmodel - see release notes and several issues:

sqlmodel 0.0.7 partly fixed the issue on their side (but notice another PR is still open), and as of sqlmodel 0.0.8 (released in August 2022) their sqlalchemy constraint is ">=1.4.17,<=1.4.41".

In fastapi-users-db-sqlmodel there are several automatic dependabot PRs to relax the constraint, but little activity.

We should verify if this package actively mantained, and otherwise we should find some way to replace it.

Note that no other dependency of ours currently requires sqlalchemy<=1.4.35:

$ poetry show sqlalchemy

 name         : sqlalchemy                   
 version      : 1.4.35                       
 description  : Database Abstraction Library 

dependencies
 - greenlet !=0.4.17

required by
 - alembic >=1.3.0
 - fastapi-users-db-sqlmodel >=1.4,<1.4.36
 - sqlalchemy-utils >=1.3
 - sqlmodel >=1.4.17,<=1.4.41
@tcompa
Copy link
Collaborator Author

tcompa commented Feb 14, 2023

For the record, let's keep in mind that https://github.com/fastapi-users/fastapi-users-db-sqlalchemy appears as well maintained.

@tcompa
Copy link
Collaborator Author

tcompa commented Mar 17, 2023

The three classes that we are using from this package are

If we proceed with a switch from UUID4 to autoincremental integer IDs (ref #560), then SQLModelBaseUserDB and SQLModelBaseOAuthAccount become irrelevant.

As per SQLModelUserDatabaseAsync, right now I find it is used eight times across github, and also see comments like these ones

Bear in mind though that we didn't officially release this DB adapter; as they are some problems with SQLModel regarding UUID (fastapi/sqlmodel#25). So you'll probably run into issues.
..
There is one that should work, but don't plan to officially support it for now: https://github.com/fastapi-users/fastapi-users-db-sqlmodel

I think that we should quickly move on and explore the possibility of fully removing this dependency. If it impossible to replace SQLModelUserDatabaseAsync, then let's also consider that it is released under MIT license and we could include that definition in our code base.

@tcompa tcompa changed the title What about fastapi-users-db-sqlmodel? Remove fastapi-users-db-sqlmodel dependency Mar 17, 2023
@tcompa tcompa mentioned this issue Mar 17, 2023
4 tasks
@caniko
Copy link

caniko commented Apr 27, 2023

Hello, would you consider supporting sqlmodel for fastapi-users?

@tcompa
Copy link
Collaborator Author

tcompa commented May 2, 2023

Hello, would you consider supporting sqlmodel for fastapi-users?

Hi there,
If you're asking whether we'd like to maintain https://github.com/fastapi-users/fastapi-users-db-sqlmodel or similar packages, I think we don't. We'll likely drop this dependency soon, and at some point we'll also need to review our use of sqlmodel in this project (as opposed to sqlalchemy v2).

@jluethi
Copy link
Collaborator

jluethi commented May 2, 2023

We being the Fractal developers, not the fastapi-users developers. You may want to check with them directly for your question @caniko , because we just use that library :)

@caniko
Copy link

caniko commented May 2, 2023

I considered the same @tcompa, thanks

@tcompa
Copy link
Collaborator Author

tcompa commented May 11, 2023

This is now ready as part of #660. The choices we made are:

  1. We merged the relevant part of SQLModelBaseUserDB into our own UserOAuth
  2. We kept SQLModelBaseOAuthAccount as is (bundled in fractal-server with attribution, under MIT license), since it is a very transparent model with a few simple (string) attributes.
  3. We kept SQLModelUserDatabaseAsync as is (bundled in fractal-server with attribution, under MIT license), since we could only re-implement it in the exact same way. If (unlikely) fastapi-users is updated in a breaking way (e.g. requiring an additional get_by_xxx method), then the current adapter won't work and some users endpoints may be break. This is mitigated by the fact that we already test all relevant fastapi-users endpoints (see test_security.py), and notably:
    • whoami
    • register
    • userlist
    • get user
    • delete user
    • patch user
    • create (super)user

Side note: if we ever move away from SQLModel, towards sqlalchemy v2, then we could revert the current change and easily switch to the (better maintained) corresponding adapter: https://github.com/fastapi-users/fastapi-users-db-sqlalchemy

@tcompa
Copy link
Collaborator Author

tcompa commented May 11, 2023

Closed with #660

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

No branches or pull requests

3 participants