<p dir="auto">Summary:<br>
Auto-reload on the development server is triggered by requests (i.e. file reads) without a file modification happening.</p>
<p dir="auto">How to reproduce:<br>
Any Flask project, having installed Watchdog version &gt;= 2.3.0. Send a request to any endpoint.</p>
<p dir="auto">Expected behavior:<br>
When sending a request to the server, the server answers and doesn't get reloaded unless a file is modified.</p>
<p dir="auto">My assumption is that the new event FileOpenedEvent added in 2.3.0 is being treated as a file modification and triggering auto-reload. Forcing watchdog version 2.2.1 fixed the problem.</p>
<p dir="auto">Environment:</p>
<ul dir="auto">
<li>Python version: 3.8</li>
<li>Flask version: 2.2.2</li>
</ul>
<p dir="auto">With Flask 2.1.0 :</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ flask test
=========================================================================== test session starts ============================================================================
platform darwin -- Python 3.10.3, pytest-7.1.2, pluggy-1.0.0 -- /Users/antoine/Documents/Git/portail/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/antoine/Documents/Git/portail
collected 29 items                                                                           
...
===================================================================== 29 passed, 5 warnings in 15.65s ======================================================================"><pre class="notranslate">$ flask <span class="pl-c1">test</span>
=========================================================================== <span class="pl-c1">test</span> session starts ============================================================================
platform darwin -- Python 3.10.3, pytest-7.1.2, pluggy-1.0.0 -- /Users/antoine/Documents/Git/portail/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/antoine/Documents/Git/portail
collected 29 items                                                                           
...
===================================================================== 29 passed, 5 warnings <span class="pl-k">in</span> 15.65s ======================================================================</pre></div>
<p dir="auto">With Flask 2.2.0 :</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="=========================================================================== test session starts ============================================================================
platform darwin -- Python 3.10.3, pytest-7.1.2, pluggy-1.0.0 -- /Users/antoine/Documents/Git/portail/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/antoine/Documents/Git/portail
collected 29 items                                                                                                                                                         

test/test_accessibility.py::TestAccessibility::test_admin_accessibility ERROR
test/test_accessibility.py::TestAccessibility::test_client_accessibility ERROR
...
========================================================================= short test summary info ==========================================================================
ERROR test/test_accessibility.py::TestAccessibility::test_admin_accessibility - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: cre_module
ERROR test/test_accessibility.py::TestAccessibility::test_client_accessibility - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: cre_module"><pre class="notranslate">=========================================================================== <span class="pl-c1">test</span> session starts ============================================================================
platform darwin -- Python 3.10.3, pytest-7.1.2, pluggy-1.0.0 -- /Users/antoine/Documents/Git/portail/venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/antoine/Documents/Git/portail
collected 29 items                                                                                                                                                         

test/test_accessibility.py::TestAccessibility::test_admin_accessibility ERROR
test/test_accessibility.py::TestAccessibility::test_client_accessibility ERROR
...
========================================================================= short <span class="pl-c1">test</span> summary info ==========================================================================
ERROR test/test_accessibility.py::TestAccessibility::test_admin_accessibility - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: cre_module
ERROR test/test_accessibility.py::TestAccessibility::test_client_accessibility - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: cre_module</pre></div>
<p dir="auto">My tables are not created in Flask 2.2.0</p>
<p dir="auto">However I didn't change anything in my tests and I don't see anything in the changelog that could affect the tests.<br>
The errors happen only when I change the version of Flask (2.1.3 --&gt; 2.2.0).</p>
<p dir="auto">Here is the code that creates the tables (which works in 2.1.3 but not in 2.2.0).</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from portail import create_app
from portail.modules import PORTAIL_MODULES, detect_modules
from portail.database import db as _db
from portail.settings import TestConfig

@pytest.fixture()
def app():
    &quot;&quot;&quot;An application for the tests.&quot;&quot;&quot;
    _app = create_app(TestConfig())

    with _app.app_context():
        _db.create_all()
        modules = detect_modules()
        for m in modules:
            m.save(False)
        _db.session.commit()
        for m in modules:
            PORTAIL_MODULES[m.id] = m
            m.expunge()

    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()

    with _app.app_context():
        _db.drop_all()

@pytest.fixture()
def db(app):
    &quot;&quot;&quot;A database for the tests.&quot;&quot;&quot;
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">portail</span> <span class="pl-k">import</span> <span class="pl-s1">create_app</span>
<span class="pl-k">from</span> <span class="pl-s1">portail</span>.<span class="pl-s1">modules</span> <span class="pl-k">import</span> <span class="pl-v">PORTAIL_MODULES</span>, <span class="pl-s1">detect_modules</span>
<span class="pl-k">from</span> <span class="pl-s1">portail</span>.<span class="pl-s1">database</span> <span class="pl-k">import</span> <span class="pl-s1">db</span> <span class="pl-k">as</span> <span class="pl-s1">_db</span>
<span class="pl-k">from</span> <span class="pl-s1">portail</span>.<span class="pl-s1">settings</span> <span class="pl-k">import</span> <span class="pl-v">TestConfig</span>

<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-en">fixture</span>()</span>
<span class="pl-k">def</span> <span class="pl-en">app</span>():
    <span class="pl-s">"""An application for the tests."""</span>
    <span class="pl-s1">_app</span> <span class="pl-c1">=</span> <span class="pl-en">create_app</span>(<span class="pl-v">TestConfig</span>())

    <span class="pl-k">with</span> <span class="pl-s1">_app</span>.<span class="pl-en">app_context</span>():
        <span class="pl-s1">_db</span>.<span class="pl-en">create_all</span>()
        <span class="pl-s1">modules</span> <span class="pl-c1">=</span> <span class="pl-en">detect_modules</span>()
        <span class="pl-k">for</span> <span class="pl-s1">m</span> <span class="pl-c1">in</span> <span class="pl-s1">modules</span>:
            <span class="pl-s1">m</span>.<span class="pl-en">save</span>(<span class="pl-c1">False</span>)
        <span class="pl-s1">_db</span>.<span class="pl-s1">session</span>.<span class="pl-en">commit</span>()
        <span class="pl-k">for</span> <span class="pl-s1">m</span> <span class="pl-c1">in</span> <span class="pl-s1">modules</span>:
            <span class="pl-v">PORTAIL_MODULES</span>[<span class="pl-s1">m</span>.<span class="pl-s1">id</span>] <span class="pl-c1">=</span> <span class="pl-s1">m</span>
            <span class="pl-s1">m</span>.<span class="pl-en">expunge</span>()

    <span class="pl-s1">ctx</span> <span class="pl-c1">=</span> <span class="pl-s1">_app</span>.<span class="pl-en">test_request_context</span>()
    <span class="pl-s1">ctx</span>.<span class="pl-en">push</span>()

    <span class="pl-k">yield</span> <span class="pl-s1">_app</span>

    <span class="pl-s1">ctx</span>.<span class="pl-en">pop</span>()

    <span class="pl-k">with</span> <span class="pl-s1">_app</span>.<span class="pl-en">app_context</span>():
        <span class="pl-s1">_db</span>.<span class="pl-en">drop_all</span>()

<span class="pl-en">@<span class="pl-s1">pytest</span>.<span class="pl-en">fixture</span>()</span>
<span class="pl-k">def</span> <span class="pl-en">db</span>(<span class="pl-s1">app</span>):
    <span class="pl-s">"""A database for the tests."""</span>
    <span class="pl-s1">_db</span>.<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-s1">app</span>
    <span class="pl-k">with</span> <span class="pl-s1">app</span>.<span class="pl-en">app_context</span>():
        <span class="pl-s1">_db</span>.<span class="pl-en">create_all</span>()

    <span class="pl-k">yield</span> <span class="pl-s1">_db</span>

    <span class="pl-c"># Explicitly close DB connection</span>
    <span class="pl-s1">_db</span>.<span class="pl-s1">session</span>.<span class="pl-en">close</span>()
    <span class="pl-s1">_db</span>.<span class="pl-en">drop_all</span>()</pre></div>
<p dir="auto">Has <code class="notranslate">app.app_context()</code> been modified or something I use for database setup?</p>
<p dir="auto">Environment:</p>
<ul dir="auto">
<li>Python version: 3.10.3</li>
<li>Flask version: 2.2.0</li>
</ul>