I use many werkzeug.local.LocalProxy objects in my Flask application. They should be ideal for objects, but this is actually not the case, as they do not respond to type () or instanceof () correctly.
They do not like SQLAlchemy at all. If I create LocalProxy to write SQLAlchemy, SQLAlchemy considers this None. If you pass it LocalProxy to a simpler type, it just says that it is the wrong type.
Here is an example of Flask-SQLAlchemy having a bad time with LocalProxy .
How do you guys deal with this problem? Just call _get_current_object () a lot? It would be great if SQLAlchemy or Flask-SQLAlchemy could automatically handle these LocalProxy objects more gracefully, especially considering that Flask-Login uses them and almost everyone uses it, right?
I am considering adding this function to my project to deal with it, and wrapping any of my local processes in it before passing them to sqlalchemy:
from werkzeug.local import LocalProxy def real(obj): if isinstance(obj, LocalProxy): return obj._get_current_object() return obj
python flask werkzeug flask-sqlalchemy sqlalchemy
Nick retallack
source share