langfield / ki

version control for Anki collections
https://langfield.github.io/ki/
GNU Affero General Public License v3.0
80 stars 3 forks source link

Database lock isn't released properly on Python 3.11 #144

Closed langfield closed 1 year ago

langfield commented 1 year ago

See below.

============================================================ FAILURES ============================================================
____________________________________________ test_no_op_pull_push_cycle_is_idempotent ____________________________________________

col_file = File('/tmp/tmpfbwlbz_0/original.anki2')

    @beartype
    def lock(col_file: File) -> sqlite3.Connection:
        """Check that lock can be acquired on a SQLite3 database given a path."""
        try:
            con = sqlite3.connect(col_file, timeout=0.1)
            con.isolation_level = "EXCLUSIVE"
>           con.execute("BEGIN EXCLUSIVE")
E           sqlite3.OperationalError: database is locked

ki/__init__.py:221: OperationalError

The above exception was the direct cause of the following exception:

    def test_no_op_pull_push_cycle_is_idempotent():
        """Do pull/push not misbehave if you keep doing both?"""
        ORIGINAL: SampleCollection = get_test_collection("original")
        runner = CliRunner()
        with runner.isolated_filesystem():

            # Clone collection in cwd.
            clone(runner, ORIGINAL.col_file)
            assert os.path.isdir(ORIGINAL.repodir)

            os.chdir(ORIGINAL.repodir)
            out = pull(runner)
            assert "Merge made by the" not in out
>           push(runner)

tests/test_integration.py:205:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
<@beartype(tests.test_ki.push) at 0x7ff83c1b7740>:48: in push
    ???
tests/test_ki.py:334: in push
    res = runner.invoke(
../conda/envs/anki11/lib/python3.11/site-packages/click/testing.py:408: in invoke
    return_value = cli.main(args=args or (), prog_name=prog_name, **extra)
../conda/envs/anki11/lib/python3.11/site-packages/click/core.py:1055: in main
    rv = self.invoke(ctx)
../conda/envs/anki11/lib/python3.11/site-packages/click/core.py:1657: in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
../conda/envs/anki11/lib/python3.11/site-packages/click/core.py:1404: in invoke
    return ctx.invoke(self.callback, **ctx.params)
../conda/envs/anki11/lib/python3.11/site-packages/click/core.py:760: in invoke
    return __callback(*args, **kwargs)
<@beartype(ki.push) at 0x7ff83c3f2020>:10: in push
    ???
ki/__init__.py:1924: in push
    con: sqlite3.Connection = lock(kirepo.col_file)
<@beartype(ki.lock) at 0x7ff83c3a6160>:31: in lock
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

col_file = File('/tmp/tmpfbwlbz_0/original.anki2')

    @beartype
    def lock(col_file: File) -> sqlite3.Connection:
        """Check that lock can be acquired on a SQLite3 database given a path."""
        try:
            con = sqlite3.connect(col_file, timeout=0.1)
            con.isolation_level = "EXCLUSIVE"
            con.execute("BEGIN EXCLUSIVE")
        except sqlite3.DatabaseError as err:
>           raise SQLiteLockError(col_file, err) from err
E           ki.types.SQLiteLockError: fatal: database is locked (Anki must not be running).

ki/__init__.py:223: SQLiteLockError