title: flask-sqlalchemy: data is not updated
body: <p>I am running SQLAlchemy with MySQL in combination with a Flask API. We use models for the requests and create and update changes with db.session.add() and db.session.commit().</p>
  
  <p>We are also running the processing of the data in parallel - its an infinite while loop which queries the database on every run (Model.query.filter_by(...).all()) - however, we only get the data that was in the database before and not the updated data - the data itself is already in the database. If we restart the application, the new data is found.</p>
  
  <p>The DB is created with db = SQLAlchemy(app) and then imported and used in the models </p>
  
  <pre><code>class Model(db.Model):
      name = db.Column(db.String(255), index=True, unique=True)
      active = db.Column(db.Boolean)
  
      def create(self):
          db.session.add(self)
          db.session.commit()
  
      def update(self):
          db.session.commit()
  
  
  def run_update():
      while True:
  
          models = Model.query.filter_by(active=True).all()
          for model in models:
              do_something(model)
              time.sleep(300)
  
  def do_something():
      longtask = threading.Thread(target=long_task)
      longtask.start()
  
  
  def long_task():
      // Update database here again
      // Task has finished before it is run again.
      time.sleep(10)
  </code></pre>
  
  <p>If a new entry is created, the result is only captured in the model query after restarting the app.</p>
  
  <p>I already tried to replace the Model.query queries with db.session.query(Model) but that did not change the result.</p>
  
  <p>Thanks in advance,</p>