Open
Description
(Apologies if this is not be the right place for this report; this is just an educated guess from the backtrace.)
Consider this simple app (which started life as the flask_migrate trivial example):
#!/bin/env python3
from flask import Flask, g, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, current_user, UserMixin
# from flask_migrate import Migrate
from config import Config # SECRET_KEY, SOCIAL_AUTH_GOOGLE_OAUTH2_KEY, SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET are in here
from social_flask.routes import social_auth
from social_flask_sqlalchemy.models import init_social
app = Flask(__name__)
login_manager = LoginManager()
# migrate = Migrate()
app.register_blueprint(social_auth)
app.config["SOCIAL_AUTH_USER_MODEL"] = "app.User"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite"
app.config["SOCIAL_AUTH_AUTHENTICATION_BACKENDS"] = ("social_core.backends.google.GoogleOAuth2",)
app.config.from_object(Config)
db = SQLAlchemy(app)
login_manager.init_app(app)
class User(UserMixin, db.Model):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
def __repr__(self):
return '<User {}>'.format(self.username)
def init_app():
init_social(app, db) # User needs to be defined before here
# migrate.init_app(app, db)
print(f"app initialised")
@login_manager.user_loader
def load_user(userid):
return User.query.get(int(userid))
@app.before_request
def global_user():
# evaluate proxy value
g.user = current_user._get_current_object()
@app.context_processor
def inject_user():
""" make g.user available (as 'user') to templates """
try:
return {"user": g.user}
except AttributeError:
return {"user": "nope"}
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
init_app()
app.run(host="127.0.0.1", port=8080, debug=True)
For completeness, the index.html template:
<!doctype html>
<html>
<head><title>Test</title></head>
<body>
{% if user.is_authenticated %}
Logged in as {{ user.username }}!
{% else %}
Not logged in - go <a href="{{ url_for('social.auth', backend='google-oauth2') }}">here</a>!
{% endif %}
</body>
</html>
The app mostly works...but while processing social.complete (returning from google, in this particular case):
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_flask/utils.py", line 43, in wrapper
return func(backend, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_flask/routes.py", line 22, in complete
return do_complete(g.backend, login=do_login, user=g.user,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/actions.py", line 49, in do_complete
user = backend.complete(user=user, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/backends/base.py", line 39, in complete
return self.auth_complete(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/utils.py", line 253, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/backends/oauth.py", line 424, in auth_complete
return self.do_auth(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/utils.py", line 253, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/backends/oauth.py", line 437, in do_auth
return self.strategy.authenticate(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/strategy.py", line 159, in authenticate
return backend.authenticate(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/backends/base.py", line 83, in authenticate
return self.pipeline(pipeline, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/backends/base.py", line 86, in pipeline
out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/backends/base.py", line 118, in run_pipeline
result = func(*args, **out) or {}
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_core/pipeline/social_auth.py", line 19, in social_user
social = backend.strategy.storage.user.get_social_auth(provider, uid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_sqlalchemy/storage.py", line 159, in get_social_auth
return cls._query().filter_by(provider=provider,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/social_sqlalchemy/storage.py", line 54, in _query
return cls._session().query(cls)
^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'module' object is not callable
I've tried to look very carefully for a dumb error at my end, but I can't for the life of me work it out.
Relevant module versions (these are all the latest available versions):
Flask==2.3.3
Flask-Login==0.6.2
Flask-SQLAlchemy==3.1.1
social-auth-app-flask==1.0.0
social-auth-app-flask-sqlalchemy==1.0.1
social-auth-core==4.4.2
social-auth-storage-sqlalchemy==1.1.0
SQLAlchemy==2.0.20
Metadata
Metadata
Assignees
Labels
No labels