Search code examples
pythonflaskflask-dance

Flask-Dance: No module named 'flask_dance.consumer.backend'


That's my very first question here, please don't eat me! I am totally newbie, I try to write a flask app using flask-dance for OAuth reason. Seems I do something stupid, because when I try to import SQLAlchemyBackend class from flask_dance.consumer.backend.sqla Python returns

ModuleNotFoundError: No module named 'flask_dance.consumer.backend'

Can you tell me please what exactly I do wrong?

I use flask-dance[sqla] version for SQLAlchemy db. First I installed basic version without SQLAlchemy support, then I uninstalled it and installed current one (all inside the venv). Is it possible that that affected the F-D functionality and its own modules and submodules scheme?

I have no idea how to fix that problem and where to go. Google doesn't help neither.

What I see in the trackback is:

Traceback (most recent call last):   File "c:\users\igor\envs\2do2\lib\site-packages\flask\cli.py", line 235, in locate_app
    __import__(module_name)   File "C:\Users\igor\projects\gp\2do2\app\app.py", line 8, in <module>
    from flask_dance.consumer.backend.sqla import SQLAlchemyBackend ModuleNotFoundError: No module named 'flask_dance.consumer.backend'

Solution

  • In Flask-Dance 1.4.0, "backends" were renamed to "storages", since the word "backend" means something different in the context of web development. This change was backwards-compatible in 1.4.0, but the backwards-compatibility features were dropped in Flask-Dance 2.0.0.

    To make this work in Flask 2.0 and above, just replace the word "backend" with the word "storage" everywhere you see it. For example, this line of code:

    from flask_dance.consumer.backend.sqla import SQLAlchemyBackend
    

    becomes this instead:

    from flask_dance.consumer.storage.sqla import SQLAlchemyStorage
    

    If you see any references to "backends" in the current documentation, please let me know! They should all be "storages" now.