<h3 dir="auto">Describe the bug</h3>
<p dir="auto">Looks  like new version is faling in <code class="notranslate">test/ext/mypy/test_mypy_plugin_py3k.py::MypyPluginTest::test_files[plain-keyfunc_dict.py]</code> unit on testing using pytest.</p>
<h3 dir="auto">To Reproduce</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.
- `python3 -sBm build -w --no-isolation`
- because I'm calling `build` with `--no-isolation` I'm using during all processes only locally installed modules
- install .whl file in &lt;/install/prefix&gt;
- run pytest with $PYTHONPATH pointing to sitearch and sitelib inside &lt;/install/prefix&gt;
- build is performed in env which is *`cut off from access to the public network`* (pytest is executed with `-m &quot;not network&quot;`)"><pre class="notranslate"><span class="pl-v">I</span><span class="pl-s">'m packaging your module as an rpm package so I'</span><span class="pl-s1">m</span> <span class="pl-s1">using</span> <span class="pl-s1">the</span> <span class="pl-s1">typical</span> <span class="pl-v">PEP517</span> <span class="pl-s1">based</span> <span class="pl-s1">build</span>, <span class="pl-s1">install</span> <span class="pl-c1">and</span> <span class="pl-s1">test</span> <span class="pl-s1">cycle</span> <span class="pl-s1">used</span> <span class="pl-s1">on</span> <span class="pl-s1">building</span> <span class="pl-s1">packages</span> <span class="pl-k">from</span> <span class="pl-s1">non</span><span class="pl-c1">-</span><span class="pl-s1">root</span> <span class="pl-s1">account</span>.
<span class="pl-c1">-</span> <span class="pl-s">`python3 -sBm build -w --no-isolation`</span>
<span class="pl-c1">-</span> <span class="pl-s1">because</span> <span class="pl-v">I</span><span class="pl-s">'m calling `build` with `--no-isolation` I'</span><span class="pl-s1">m</span> <span class="pl-s1">using</span> <span class="pl-s1">during</span> <span class="pl-s1">all</span> <span class="pl-s1">processes</span> <span class="pl-s1">only</span> <span class="pl-s1">locally</span> <span class="pl-s1">installed</span> <span class="pl-s1">modules</span>
<span class="pl-c1">-</span> <span class="pl-s1">install</span> .<span class="pl-s1">whl</span> <span class="pl-s1">file</span> <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-s1">install</span><span class="pl-c1">/</span><span class="pl-s1">prefix</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">-</span> <span class="pl-s1">run</span> <span class="pl-s1">pytest</span> <span class="pl-k">with</span> $<span class="pl-v">PYTHONPATH</span> <span class="pl-s1">pointing</span> <span class="pl-s1">to</span> <span class="pl-s1">sitearch</span> <span class="pl-c1">and</span> <span class="pl-s1">sitelib</span> <span class="pl-s1">inside</span> <span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-s1">install</span><span class="pl-c1">/</span><span class="pl-s1">prefix</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">-</span> <span class="pl-s1">build</span> <span class="pl-c1">is</span> <span class="pl-s1">performed</span> <span class="pl-c1">in</span> <span class="pl-s1">env</span> <span class="pl-s1">which</span> <span class="pl-c1">is</span> <span class="pl-c1">*</span><span class="pl-s">`cut off from access to the public network`</span><span class="pl-c1">*</span> (<span class="pl-s1">pytest</span> <span class="pl-c1">is</span> <span class="pl-s1">executed</span> <span class="pl-s1">with</span> <span class="pl-s">`-m "not network"`</span>)</pre></div>
<h3 dir="auto">Error</h3>
<p dir="auto">Here is pytest output</p>
<h3 dir="auto">Versions</h3>
<ul dir="auto">
<li>OS: Linux</li>
<li>Python: 3.8.16</li>
<li>SQLAlchemy: 2.0.2</li>
<li>Database: N/A</li>
<li>DBAPI (eg: psycopg, cx_oracle, mysqlclient): N/A</li>
</ul>
<h3 dir="auto">Additional context</h3>
<p dir="auto">Here is list of installed modules in build env</p>
<details>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Package                       Version
----------------------------- -----------------
alabaster                     0.7.13
appdirs                       1.4.4
attrs                         22.2.0
Babel                         2.11.0
build                         0.9.0
changelog                     0.5.8
charset-normalizer            3.0.1
cssselect                     1.1.0
Cython                        0.29.33
distro                        1.8.0
docutils                      0.19
exceptiongroup                1.0.0
execnet                       1.9.0
extras                        1.0.0
fixtures                      4.0.0
gpg                           1.18.0-unknown
greenlet                      1.1.3
idna                          3.4
imagesize                     1.4.1
importlib-metadata            6.0.0
iniconfig                     2.0.0
Jinja2                        3.1.2
libcomps                      0.1.19
lxml                          4.9.2
Markdown                      3.4.1
MarkupSafe                    2.1.1
mypy                          0.990
mypy-extensions               0.4.3
numpy                         1.24.1
olefile                       0.46
packaging                     23.0
pbr                           5.9.0
pep517                        0.13.0
Pillow                        9.4.0
pip                           22.3.1
pluggy                        1.0.0
Pygments                      2.14.0
PyGObject                     3.43.1.dev0
pytest                        7.2.1
pytest-xdist                  3.1.0
python-dateutil               2.8.2
pytz                          2022.4
requests                      2.28.2
rpm                           4.17.0
scour                         0.38.2
setuptools                    65.6.3
six                           1.16.0
smartypants                   2.0.1
snowballstemmer               2.2.0
Sphinx                        6.1.3
sphinx-copybutton             0.5.1
sphinx-paramlinks             0.5.2
sphinxcontrib-applehelp       1.0.2.dev20221204
sphinxcontrib-devhelp         1.0.2.dev20230202
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1.dev20230128
sphinxcontrib-qthelp          1.0.3.dev20230128
sphinxcontrib-serializinghtml 1.1.5
testtools                     2.5.0
toml                          0.10.2
tomli                         2.0.1
typing_extensions             4.4.0
typogrify                     2.0.7
urllib3                       1.26.12
wheel                         0.38.4
zipp                          3.12.0"><pre class="notranslate"><span class="pl-c1">Package                       Version</span>
<span class="pl-c1">----------------------------- -----------------</span>
<span class="pl-c1">alabaster                     0.7.13</span>
<span class="pl-c1">appdirs                       1.4.4</span>
<span class="pl-c1">attrs                         22.2.0</span>
<span class="pl-c1">Babel                         2.11.0</span>
<span class="pl-c1">build                         0.9.0</span>
<span class="pl-c1">changelog                     0.5.8</span>
<span class="pl-c1">charset-normalizer            3.0.1</span>
<span class="pl-c1">cssselect                     1.1.0</span>
<span class="pl-c1">Cython                        0.29.33</span>
<span class="pl-c1">distro                        1.8.0</span>
<span class="pl-c1">docutils                      0.19</span>
<span class="pl-c1">exceptiongroup                1.0.0</span>
<span class="pl-c1">execnet                       1.9.0</span>
<span class="pl-c1">extras                        1.0.0</span>
<span class="pl-c1">fixtures                      4.0.0</span>
<span class="pl-c1">gpg                           1.18.0-unknown</span>
<span class="pl-c1">greenlet                      1.1.3</span>
<span class="pl-c1">idna                          3.4</span>
<span class="pl-c1">imagesize                     1.4.1</span>
<span class="pl-c1">importlib-metadata            6.0.0</span>
<span class="pl-c1">iniconfig                     2.0.0</span>
<span class="pl-c1">Jinja2                        3.1.2</span>
<span class="pl-c1">libcomps                      0.1.19</span>
<span class="pl-c1">lxml                          4.9.2</span>
<span class="pl-c1">Markdown                      3.4.1</span>
<span class="pl-c1">MarkupSafe                    2.1.1</span>
<span class="pl-c1">mypy                          0.990</span>
<span class="pl-c1">mypy-extensions               0.4.3</span>
<span class="pl-c1">numpy                         1.24.1</span>
<span class="pl-c1">olefile                       0.46</span>
<span class="pl-c1">packaging                     23.0</span>
<span class="pl-c1">pbr                           5.9.0</span>
<span class="pl-c1">pep517                        0.13.0</span>
<span class="pl-c1">Pillow                        9.4.0</span>
<span class="pl-c1">pip                           22.3.1</span>
<span class="pl-c1">pluggy                        1.0.0</span>
<span class="pl-c1">Pygments                      2.14.0</span>
<span class="pl-c1">PyGObject                     3.43.1.dev0</span>
<span class="pl-c1">pytest                        7.2.1</span>
<span class="pl-c1">pytest-xdist                  3.1.0</span>
<span class="pl-c1">python-dateutil               2.8.2</span>
<span class="pl-c1">pytz                          2022.4</span>
<span class="pl-c1">requests                      2.28.2</span>
<span class="pl-c1">rpm                           4.17.0</span>
<span class="pl-c1">scour                         0.38.2</span>
<span class="pl-c1">setuptools                    65.6.3</span>
<span class="pl-c1">six                           1.16.0</span>
<span class="pl-c1">smartypants                   2.0.1</span>
<span class="pl-c1">snowballstemmer               2.2.0</span>
<span class="pl-c1">Sphinx                        6.1.3</span>
<span class="pl-c1">sphinx-copybutton             0.5.1</span>
<span class="pl-c1">sphinx-paramlinks             0.5.2</span>
<span class="pl-c1">sphinxcontrib-applehelp       1.0.2.dev20221204</span>
<span class="pl-c1">sphinxcontrib-devhelp         1.0.2.dev20230202</span>
<span class="pl-c1">sphinxcontrib-htmlhelp        2.0.0</span>
<span class="pl-c1">sphinxcontrib-jsmath          1.0.1.dev20230128</span>
<span class="pl-c1">sphinxcontrib-qthelp          1.0.3.dev20230128</span>
<span class="pl-c1">sphinxcontrib-serializinghtml 1.1.5</span>
<span class="pl-c1">testtools                     2.5.0</span>
<span class="pl-c1">toml                          0.10.2</span>
<span class="pl-c1">tomli                         2.0.1</span>
<span class="pl-c1">typing_extensions             4.4.0</span>
<span class="pl-c1">typogrify                     2.0.7</span>
<span class="pl-c1">urllib3                       1.26.12</span>
<span class="pl-c1">wheel                         0.38.4</span>
<span class="pl-c1">zipp                          3.12.0</span></pre></div>
</details>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">If a trigger in SQLite raises ROLLBACK, the exception that is propogated to the application is always "OperationalError: SQL logic error or missing database".  Here is an example that illustrates the problem (I have attached this file):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sqlalchemy import *
import sqlite3
DB_NAME = 'test.db3'

def set_up_database():
    **
    Make a simple table with one (primary key) column, and a trigger that 
    prevents deletion from the table.  Also puts a row into the table.
    **
    conn = sqlite3.connect(DB_NAME)
    cursor = conn.cursor()
    cursor.executescript(**
    DROP TABLE IF EXISTS test_table;
    CREATE TABLE test_table(name VARCHAR(10) NOT NULL PRIMARY KEY);
    CREATE TRIGGER delete_test_table
        BEFORE DELETE ON &quot;test_table&quot;
        FOR EACH ROW BEGIN
          SELECT RAISE(ROLLBACK, 'Cannot delete from table &quot;test_table&quot;');
        END;    
    INSERT INTO test_table(name) VALUES('first');
    **)
    cursor.close()
    conn.close()
    
def test_direct_insert():
    **
    Attempt to duplicate a primary key using direct sqlite3 access.  The
    exception message should indicate the problem, and it does:
        test_direct() insert duplicate error: column name is not unique
    **
    conn = sqlite3.connect(DB_NAME)
    cursor = conn.cursor()
    try:
        cursor.execute('INSERT INTO test_table(name) VALUES(?)', ('first',))
    except Exception, e:
        print 'test_direct() insert duplicate error: %s' % e
    finally:
        cursor.close()
        conn.close()

def test_direct_delete():
    **
    Attempt to delete a row using direct sqlite3 access, but the table's
    trigger prevents all deletion.  The exception message should indicate 
    the problem, and it does:
        test_direct() deletion error: Cannot delete from table &quot;test_table&quot;
    **
    conn = sqlite3.connect(DB_NAME)
    cursor = conn.cursor()
    try:
        cursor.execute('DELETE FROM test_table WHERE name=?', ('first',))
    except Exception, e:
        print 'test_direct() deletion error: %s' % e
    finally:
        cursor.close()
        conn.close()
        
def test_sqlalchemy_insert():        
    **
    Attempt to duplicate a primary key through SQLAlchemy.  The
    exception message should indicate the problem, and it does:
        test_sqlalchemy() insert duplicate error: (IntegrityError) column name is
        not unique u'INSERT INTO test_table (name) VALUES (?)' ['first']('first')    
    **
    db = create_engine('sqlite:///%s' % DB_NAME)
    metadata = MetaData(db)
    table = Table('test_table', metadata, autoload=True)
    #metadata.engine.echo = True
    insert_statement = table.insert()
    try:
        insert_statement.execute(name='first')
    except Exception, e:
        print 'test_sqlalchemy() insert duplicate error: %s' % e
   
def test_sqlalchemy_delete():        
    **
    Attempt to delete a row through SQLAlchemy, but the table's trigger 
    prevents all deletion.  The exception message should indicate the 
    problem, BUT it displays instead:
        test_sqlalchemy() deletion error: (OperationalError) SQL logic error
        or missing database None None
    **
    db = create_engine('sqlite:///%s' % DB_NAME)
    metadata = MetaData(db)
    table = Table('test_table', metadata, autoload=True)
    #metadata.engine.echo = True
    delete_statement = table.delete()
    try:
        delete_statement.execute(name='first')
    except Exception, e:
        print 'test_sqlalchemy() deletion error: %s' % e
        
if __name__ == '__main__':
    set_up_database()
    test_direct_insert() # Works fine.
    test_direct_delete() # Works fine.
    test_sqlalchemy_insert() # Works fine.
    test_sqlalchemy_delete() # Doesn't work correctly."><pre class="notranslate"><code class="notranslate">from sqlalchemy import *
import sqlite3
DB_NAME = 'test.db3'

def set_up_database():
    **
    Make a simple table with one (primary key) column, and a trigger that 
    prevents deletion from the table.  Also puts a row into the table.
    **
    conn = sqlite3.connect(DB_NAME)
    cursor = conn.cursor()
    cursor.executescript(**
    DROP TABLE IF EXISTS test_table;
    CREATE TABLE test_table(name VARCHAR(10) NOT NULL PRIMARY KEY);
    CREATE TRIGGER delete_test_table
        BEFORE DELETE ON "test_table"
        FOR EACH ROW BEGIN
          SELECT RAISE(ROLLBACK, 'Cannot delete from table "test_table"');
        END;    
    INSERT INTO test_table(name) VALUES('first');
    **)
    cursor.close()
    conn.close()
    
def test_direct_insert():
    **
    Attempt to duplicate a primary key using direct sqlite3 access.  The
    exception message should indicate the problem, and it does:
        test_direct() insert duplicate error: column name is not unique
    **
    conn = sqlite3.connect(DB_NAME)
    cursor = conn.cursor()
    try:
        cursor.execute('INSERT INTO test_table(name) VALUES(?)', ('first',))
    except Exception, e:
        print 'test_direct() insert duplicate error: %s' % e
    finally:
        cursor.close()
        conn.close()

def test_direct_delete():
    **
    Attempt to delete a row using direct sqlite3 access, but the table's
    trigger prevents all deletion.  The exception message should indicate 
    the problem, and it does:
        test_direct() deletion error: Cannot delete from table "test_table"
    **
    conn = sqlite3.connect(DB_NAME)
    cursor = conn.cursor()
    try:
        cursor.execute('DELETE FROM test_table WHERE name=?', ('first',))
    except Exception, e:
        print 'test_direct() deletion error: %s' % e
    finally:
        cursor.close()
        conn.close()
        
def test_sqlalchemy_insert():        
    **
    Attempt to duplicate a primary key through SQLAlchemy.  The
    exception message should indicate the problem, and it does:
        test_sqlalchemy() insert duplicate error: (IntegrityError) column name is
        not unique u'INSERT INTO test_table (name) VALUES (?)' ['first']('first')    
    **
    db = create_engine('sqlite:///%s' % DB_NAME)
    metadata = MetaData(db)
    table = Table('test_table', metadata, autoload=True)
    #metadata.engine.echo = True
    insert_statement = table.insert()
    try:
        insert_statement.execute(name='first')
    except Exception, e:
        print 'test_sqlalchemy() insert duplicate error: %s' % e
   
def test_sqlalchemy_delete():        
    **
    Attempt to delete a row through SQLAlchemy, but the table's trigger 
    prevents all deletion.  The exception message should indicate the 
    problem, BUT it displays instead:
        test_sqlalchemy() deletion error: (OperationalError) SQL logic error
        or missing database None None
    **
    db = create_engine('sqlite:///%s' % DB_NAME)
    metadata = MetaData(db)
    table = Table('test_table', metadata, autoload=True)
    #metadata.engine.echo = True
    delete_statement = table.delete()
    try:
        delete_statement.execute(name='first')
    except Exception, e:
        print 'test_sqlalchemy() deletion error: %s' % e
        
if __name__ == '__main__':
    set_up_database()
    test_direct_insert() # Works fine.
    test_direct_delete() # Works fine.
    test_sqlalchemy_insert() # Works fine.
    test_sqlalchemy_delete() # Doesn't work correctly.
</code></pre></div>
<p dir="auto">I have tried to find the source of the problem, and it looks like it might be in sqlalchemy.engine.default.do_rollback().  Apparently, the connection.rollback() statement is raising the OperationalError.  Note that the error happens only for triggers, not other constraints.</p>
<p dir="auto">For now, I trap the OperationalError in do_rollback() and toss it, so the original IntegrityError gets propogated to my application.  However, I'm not sure whether there is a more-serious underlying problem.</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/698/sqlite_trigger_problem.py">sqlite_trigger_problem.py</a></p>