0

Within an Flask app I'm polling my database waiting for an given record to appear:

for i in range(10):
    shop = Shop.query.filter_by(id=shop_id).one_or_none()
    if shop:
       # break and do something
    sleep(60)

However even if the shop record appears, the query always gives None (if the first iteration was None), even if the same SQL query return an object. It almost looks like SQLalchemy (1.3) uses some kind of caching instead of really executing evaluating the result of the query!

The same behavious is true in the opposite direction as well i.e. if the shop record is deleted from the database.

sonium
  • 918
  • 1
  • 11
  • 25
  • Yes, commiting before solves the issue - but how is this not a bug? – sonium Feb 21 '22 at 12:30
  • 1
    See [this answer](https://stackoverflow.com/a/10212030/5320906) but this is the default behaviour for many RDBMS: once your start a transaction you work with a snapshot of the current state of the database, and that snapshot is not updated until you commit. – snakecharmerb Feb 21 '22 at 12:46

0 Answers0