title: LocalProxy objects in Flask-SQLAlchemy
body: <p>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.</p>
  
  <p>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.</p>
  
  <p><a href="https://gist.github.com/nickretallack/ec096a8013046c42d8f9" rel="noreferrer">Here's an example of Flask-SQLAlchemy having a bad time with LocalProxy</a>.</p>
  
  <p>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?</p>
  
  <p>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:</p>
  
  <pre><code>from werkzeug.local import LocalProxy
  
  def real(obj):
      if isinstance(obj, LocalProxy):
          return obj._get_current_object()
      return obj
  </code></pre>