flask-sqlalchemy icon indicating copy to clipboard operation
flask-sqlalchemy copied to clipboard

Implement support for custom sessions

Open justanr opened this issue 8 years ago • 10 comments

Backwards compatible change to address #327

~~I'm of two minds about the place in the documentation. I was thinking of merging the customizing and configuration pages into one (which is what I should've done in the first place >_>).~~

~~Otherwise, I think this is a straight forward change.~~

Update: Rebased onto master including converting the custom session test to py.test and moved the documentation of custom sessions into the customization sections.

justanr avatar Jan 02 '17 22:01 justanr

I came here to implement this myself, glad to see it's already been done. LGTM :+1:

TRManderson avatar Jan 27 '17 02:01 TRManderson

Ping @immunda @davidism Have either of you had a chance to review this?

I noticed that the Py3.4 Lowest tests fail on the scopefunc test -- I'm not sure if that is a regression or something flaky that happens. I noticed it happened in a master build a few builds ago.

Also, the TRACK_MODIFICATIONS and unset database URI warnings create a lot of noise in the tests -- did I screw something up with a rebase, it doesn't look like other branches have this issue.

justanr avatar Jun 13 '17 01:06 justanr

Sorry, I'm really stretched thin and don't have a lot of time to divide between a lot of projects. I need to get back to Flask-SQLAlchemy after I've finished with Flask. Just letting you know that the project's not abandoned, and I will get to this.

davidism avatar Jun 13 '17 02:06 davidism

Rebased onto latest master again and it looks the errors aren't a thing anymore.

justanr avatar Sep 25 '17 23:09 justanr

@davidism You brought up in #545 that scoped_session only proxies public Session methods, however I can't find a location to reference this in the SQLA documentation, am I overlooking something?

justanr avatar Oct 05 '17 01:10 justanr

I looked at the source: https://bitbucket.org/zzzeek/sqlalchemy/src/2c280791886756422a8103769cf131b0fe292ffe/lib/sqlalchemy/orm/scoping.py?at=master&fileviewer=file-view-default#scoping.py-151:157

def instrument(name):
    def do(self, *args, **kwargs):
        return getattr(self.registry(), name)(*args, **kwargs)
    return do

for meth in Session.public_methods:
    setattr(scoped_session, meth, instrument(meth))

At startup, adds proxy methods to scoped_session only for methods specified in Session.public_methods.

davidism avatar Oct 05 '17 01:10 davidism

hm, odd it isn't documented. I'll add a warning to the docs tomorrow then. It's there anything else that needs updating with this PR? Should it still target a 3.0 release?

justanr avatar Oct 05 '17 02:10 justanr

@davidism poke. Is there still interest in merging this PR?

justanr avatar May 10 '18 02:05 justanr

I believe this is related to #438.

rsyring avatar Mar 08 '19 21:03 rsyring

@davidism any news on if this will get merged up or needs updated in any way? This functionality would be incredibly useful.

Zomgnomes avatar Oct 22 '21 13:10 Zomgnomes

Fixed in #1087

davidism avatar Sep 18 '22 16:09 davidism