# Buggy code
def __run_transaction_with_foreign_keys_disabled(
    self, fun: Callable[[sqlite3.Connection, Any, Any], Any], *args, **kwargs
):
    (foreign_keys_enabled,) = self.connection.execute("pragma foreign_keys").fetchone()
    if not foreign_keys_enabled:
        raise sqlite3.IntegrityError(
            "foreign keys are disabled, use `AIOSQLite.run` instead"
        )
    try:
        self.connection.execute("pragma foreign_keys=off")
        return self.__run_transaction(fun, *args, **kwargs)
    finally:
        self.connection.execute("pragma foreign_keys=on")


# Traceback (sqlite3.InterfaceError)
2019-05-22 11:29:08,217 INFO     torba.client.baseledger:125: (lbc_mainnet) on_address: ['bRFrdNffbqpmLnJDv9n3WPXHSQZx3jbQ9d', 'bCooREDfWchZp2W3J3sp4cpYFTwFgjs4HB', 'bJ4t5xDH3VaCn9tyjf2SGKr9E5NWsTVoZa', 'bR8NvBkV4FKzm3GsrLTLpEdajoPSin86Hg', 'bGuS42xgcRH6eVoXmFusiie2z85v4fbkm5', 'bWc6ZgefAwqvKddQGhbnuNuGe5Qdt3JyS5', 'bGVmKgRnPHq9XWthMoVkJYhP6fM3FuZjFC', 'bZKK6irm4fKg1RrsZA7vTBMuDk7JruSkCe', 'bEWAJXE7uYckDKTzkEREUfnC5Rw4y5y8fa', 'bKMV41fHzU5a3c32HJ42ZL39jXprz9muze', 'bRu9SZhSwrKiPhJEoDSXMsb7JyHmJRg13C', 'bH3J7FnNPtA8RC4CL7pLYZcRBuDE3dfzgk', 'bPwfPQTUTPncazeeJdrNcTYhjKkLQkRDNJ', 'bRaQP4JbgTDJbgvbJaYWNVHzpBoi3TDHGD', 'bWt4UvNRbUqwbJtW5gUabEj3dG2uaRVJzD', 'bUKFnd7uSnFyQbvqvpdK3MGvRA8HccuqYt', 'bEsC4CeSCP5sRsnMgt8G7L2HewrwRzg3en', 'baASTNc6t6V82wNrgSwvwuYK3s6Uga93w7', 'bL5vFyUvzazUkWdgqG1ZRQksW1zBP6KWb5', 'bUqVumd8AYbCNDkvSTPbcN24K7Lk5SnFkm']
2019-05-22 11:29:08,229 INFO     torba.client.baseledger:125: (lbc_mainnet) on_address: ['bLrEADwdXaTuzqJp74JaQ2oKd7TabEAuEX', 'bCvuQRyHLBS1RsQUzYRYvu4FQsVLkB8CqG', 'bRmhdKXXaWJVQP9rc4g6cXzzyoJM5qsDMg', 'bTz5yM5yn19gMTQoJJyUBgubJ34nkuViqh', 'bQ5mfFViSU8b69uNcESfteoF1pAoC2XNrs', 'bCvjVRgnKm28CBLZNDGWHGos2Dv5QL4byA', 'bFLvefdk1Da2GB5oxVZXsK4PZ8Bs24Ghbf', 'bMtWobUFJMutGJ6o5UHN4EAHtK3NnRoxu5', 'bD45BgoG6DxywWzZKY6fbf787M1v2ZgVgZ', 'bEcykVNdYmK9M5JNaCPgfcr1qeK78jGYGf', 'bJZa3GrhWs4u7NZyHgZutaPybQGGeMy1cY', 'bap8B9oci9y1uCPQYbJaguE6ty3N8UnBvM', 'bH7jrnURyV4Azmit8LcfdMgQST5sdhTKx8', 'bNR2EWJGXbU24zxsu1wAw139vwJvmcVizs', 'bM6j8GyvRxZ6xL1kwnKm6TXwYeU3D8CYGS', 'bHcemnXEnisLAouvk3amqXx8X1BfJrTThT', 'bKxxwYWqjsjX9yYwgygWzNGkMYD48UbuYm', 'bP8yrGLewLZKJ8T9EaPXVYWJdNY5Po9V8S', 'bMYhng5tGaa88X62DfnWynmSdM6aPVQamF', 'bHQrTNGLHkMrwZETJaFcD2RwLKdkoQV1oR']
Task exception was never retrieved
future: <Task finished coro=<BaseLedger.subscribe_account() done, defined at c:\users\thoma\documents\lbry\torba\torba\client\baseledger.py:344> exception=InterfaceError('Error binding parameter 0 - probably unsupported type.')>
Traceback (most recent call last):
File "c:\users\thoma\documents\lbry\torba\torba\client\baseledger.py", line 347, in subscribe_account
await account.ensure_address_gap()
File "c:\users\thoma\documents\lbry\torba\torba\client\baseaccount.py", line 375, in ensure_address_gap
new_addresses = await address_manager.ensure_address_gap()
File "c:\users\thoma\documents\lbry\torba\torba\client\baseaccount.py", line 139, in ensure_address_gap
new_keys = await self._generate_keys(start, end-1)
File "c:\users\thoma\documents\lbry\torba\torba\client\baseaccount.py", line 147, in _generate_keys
await self.account.ledger.db.add_keys(self.account, self.chain_number, keys)
File "c:\users\thoma\documents\lbry\torba\torba\client\basedatabase.py", line 516, in add_keys
for position, pubkey in keys)
File "C:\Users\thoma\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "c:\users\thoma\documents\lbry\torba\torba\client\basedatabase.py", line 61, in __run_transaction
result = fun(self.connection, *args, **kwargs)  # type: ignore
File "c:\users\thoma\documents\lbry\torba\torba\client\basedatabase.py", line 39, in __executemany_in_a_transaction
return conn.executemany(*args, **kwargs)
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
2019-05-22 11:29:08,305 INFO     torba.client.baseledger:118: (lbc_mainnet) on_transacti

# Fixed code
def __run_transaction_with_foreign_keys_disabled(
    self, fun: Callable[[sqlite3.Connection, Any, Any], Any], args, kwargs
):
    (foreign_keys_enabled,) = self.connection.execute("pragma foreign_keys").fetchone()
    if not foreign_keys_enabled:
        raise sqlite3.IntegrityError(
            "foreign keys are disabled, use `AIOSQLite.run` instead"
        )
    try:
        self.connection.execute("pragma foreign_keys=off")
        return self.__run_transaction(fun, *args, **kwargs)
    finally:
        self.connection.execute("pragma foreign_keys=on")