-
-
Notifications
You must be signed in to change notification settings - Fork 901
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
fix: session get bind signature #955
Conversation
Needs to be rebased to 2.x branch, since it's a fix against 2.x. You don't need to re-request my review, I get notifications on events already. |
4bfebc1
to
070bf10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding *args
is less fragile
I can do that, but if this affects master wouldn't it be desirable to merge this to master, then cherry pick into 2.x? I can also open a new PR from 2.x to 2.x with this patch? |
I'd love to know what is causing the default args to be put in to args in the first place. From some playing it's something to do with the scoped_session/session factory. This doesn't work without this PR or something like it: session.get_bind() But this does: session().get_bind() |
For sure, on SQLAlchemy < 1.4 was pretty simple, But now, I confess I don't follow what is going on |
This seems to be the source of the extra arguments. @zzzeek Is there a particular reason the proxy is including the defaults as explicit parameters, rather than letting python defaults do their thing? (i.e. using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to have to use the *args approach as SQLA 1.3 only has 2 args.
(That, or update the dep on SQLAlchemy to >=1.4)
Edit: Daniel gave me access to his fork, and I've made this change there
I would assume so they get included in the docstrings. im not seeing the whole context here, it looks like you're subclassing Session which is fine. Is it going wrong with scoped_session()? |
@zzzeek Yeah, subclassing Session. Given the dynamic function is via a string-eval, that won't show up in docstrings I don't think? Isn't Very rough reproduction steps class ExpSQLAlchemy(SQLAlchemy):
def create_session(self, options):
return sessionmaker(class_=SignallingSession, db=self, **options)
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"
db = ExpSQLAlchemy(app)
session = db.session
# This is fine
print(db.session().get_bind())
# This errors with "wrong number of positional arguments)
print(session.get_bind()) Because of the subclassing as it was defined; def get_bind(self, mapper=None, **kwargs): that used to work, but on SQLA 1.4 that now doesn't, as the proxy code passes them all as positional. |
not sure if you noticed check out sqlalchemy/sqlalchemy#6285 but I just put out 1.4.8, so might not get to this for some days |
@zzzeek Thank you |
Going to close this, since SQLAlchemy is fixed and flask-sqlalchemy master looks good now |
The
SignallingSession
get_bind
is being called without any parameters, this is probably due to the new SQLAlchemy proxied mechanism for registering scoped sessionsThis is a simple fix that just uses the exact method signature from SQLAlchemy for get_bind of the current session
Checklist:
CHANGES.rst
summarizing the change and linking to the issue... versionchanged::
entries in any relevant code docs.pre-commit
hooks and fix any issues.pytest
andtox
, no tests failed.