I'm using a lot of werkzeug.local.LocalProxy objects in my Flask app. They are supposed to be perfect stand-ins for objects, but they aren't really, since they don't respond to type() or instanceof() correctly.
SQLAlchemy doesn't like them at all. If I make a LocalProxy to a SQLAlchemy record, SQLAlchemy considers it to be None. If I pass it a LocalProxy to a simpler type, it just says it's the wrong type.
How do you guys deal with this problem? Just call _get_current_object() a lot? It'd be pretty cool if SQLAlchemy or Flask-SQLAlchemy could automatically handle these LocalProxy objects more gracefully, especially considering Flask-Login uses them, and pretty much everybody uses that, right?
I'm considering adding this function to my project to deal with it, and wrapping any of my localproxies in it before passing them to sqlalchemy:
from werkzeug.local import LocalProxydef real(obj): if isinstance(obj, LocalProxy): return obj._get_current_object() return obj