Bug: ImportError: cannot import name 'SQLAlchemyBaseUserTableUUID' from 'fastapi_users.db'

See original GitHub issue

The bug in short:

from fastapi_users.db import SQLAlchemyBaseUserTableUUID
ImportError: cannot import name 'SQLAlchemyBaseUserTableUUID' from 'fastapi_users.db'

This code is also placed here: https://github.com/fastapi-users/fastapi-users/blob/3e44abdbeffbe529120f96a91e1f4499202bbe2f/examples/sqlalchemy/app/db.py#L4

And here: https://fastapi-users.github.io/fastapi-users/10.1/configuration/full-example/#sqlalchemy

Most likely similar to https://github.com/fastapi-users/fastapi-users/issues/1071#issue-1360728701

Environment:

david@david-ThinkPad-T14s-Gen-2i:~$ python3 -V
Python 3.10.4
david@david-ThinkPad-T14s-Gen-2i:~$ pip -V
pip 22.2.2 from /home/david/.local/lib/python3.10/site-packages/pip (python 3.10)
david@david-ThinkPad-T14s-Gen-2i:~$ python3 -m venv /home/david/test_venv
david@david-ThinkPad-T14s-Gen-2i:~$ source test_venv/bin/activate
(test_venv) david@david-ThinkPad-T14s-Gen-2i:~$ pip install fastapi-users
Collecting fastapi-users
# ... Installation process here (success)
(test_venv) david@david-ThinkPad-T14s-Gen-2i:~$ python3 -V  # Version inside venv
Python 3.10.4
(test_venv) david@david-ThinkPad-T14s-Gen-2i:~$ pip -V  # Version inside venv
pip 22.0.2 from /home/david/test_venv/lib/python3.10/site-packages/pip (python 3.10)
david@david-ThinkPad-T14s-Gen-2i:~$ uname -a
Linux david-ThinkPad-T14s-Gen-2i 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
david@david-ThinkPad-T14s-Gen-2i:~$ pip show fastapi-users
Name: fastapi-users
Version: 10.1.5
Summary: Ready-to-use and customizable users management for FastAPI
Home-page: 
Author: 
Author-email: François Voron <fvoron@gmail.com>
License: 
Location: /home/david/.local/lib/python3.10/site-packages
Requires: email-validator, fastapi, makefun, passlib, pyjwt, python-multipart
Required-by:

The bug:

(test_venv) david@david-ThinkPad-T14s-Gen-2i:~$ python3
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from fastapi_users.db import SQLAlchemyBaseUserTableUUID
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'SQLAlchemyBaseUserTableUUID' from 'fastapi_users.db' (/home/david/test_venv/lib/python3.10/site-packages/fastapi_users/db/__init__.py)
>>> import fastapi_users.db
>>> fastapi_users.db.SQLAlchemyBaseUserTableUUID
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'fastapi_users.db' has no attribute 'SQLAlchemyBaseUserTableUUID'

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
david-shikocommented, Sep 15, 2022

You need to install the optional dependency for SQAlchemy:

pip install 'fastapi-users[sqlalchemy]'

https://fastapi-users.github.io/fastapi-users/10.1/installation/#with-sqlalchemy-support

BTW IMHO it’s better to create a special error if no the required additional extension was installed to eliminate errors of such kind.

1reaction
frankie567commented, Sep 12, 2022

No problem! Sometimes, Python virtual environments behave weirdly 🙃

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: FastAPI-users - python - Stack Overflow
Please use only fully-qualified module names, and not relative ones as we'd then fail to find the module to bind models to the...
Read more >
separate mongodb dependency for tests and packaged code
Projects. FastAPI Users planning ... importing fastapi_user after $ pip install ... ModuleNotFoundError: No module named 'motor'.
Read more >
fastapi-users-db-sqlalchemy - PyPI
Add quickly a registration and authentication system to your FastAPI project. FastAPI Users is designed to be as customizable and adaptable as possible....
Read more >
tiangolo/fastapi - Gitter
Previously, I had been importing db = SessionLocal() into my app.models file, ... the less geting an import error ImportError: cannot import name...
Read more >
fastapi-users - bytemeta
fastapi-users repo issues. ... DB schema not created with additional fields ... Bug: ImportError: cannot import name 'SQLAlchemyBaseUserTableUUID' from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found