# Buggy code
async def remove_instance(
    instance,
    interactive: bool = False,
    delete_data: Optional[bool] = None,
    _create_backup: Optional[bool] = None,
    drop_db: Optional[bool] = None,
    remove_datapath: Optional[bool] = None,
):
    data_manager.load_basic_configuration(instance)

    if interactive is True and delete_data is None:
        delete_data = click.confirm(
            "Would you like to delete this instance's data?", default=False
        )

    if interactive is True and _create_backup is None:
        _create_backup = click.confirm(
            "Would you like to make a backup of the data for this instance?",
            default=False,
        )

    if _create_backup is True:
        await create_backup(instance)

    backend = get_current_backend(instance)
    driver_cls = drivers.get_driver_class(backend)

    if delete_data is True:
        await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)

    if interactive is True and remove_datapath is None:
        remove_datapath = click.confirm(
            "Would you like to delete the instance's entire datapath?", default=False
        )

    if remove_datapath is True:
        data_path = data_manager.core_data_path().parent
        safe_delete(data_path)

    save_config(instance, {}, remove=True)
    print("The instance {} has been removed\n".format(instance))


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/julien/red/bin/redbot-setup", line 8, in <module>
sys.exit(run_cli())
File "/home/julien/red/lib/python3.8/site-packages/redbot/setup.py", line 429, in run_cli
cli()  # pylint: disable=no-value-for-parameter  # click
File "/home/julien/red/lib/python3.8/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/julien/red/lib/python3.8/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/julien/red/lib/python3.8/site-packages/click/core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/julien/red/lib/python3.8/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/julien/red/lib/python3.8/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/home/julien/red/lib/python3.8/site-packages/redbot/setup.py", line 372, in delete
loop.run_until_complete(
File "/home/julien/.pyenv/versions/3.8.1/lib/python3.8/asyncio/base_events.py", line 612, in run_until_complete
return future.result()
File "/home/julien/red/lib/python3.8/site-packages/redbot/setup.py", line 258, in remove_instance
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
File "/home/julien/red/lib/python3.8/site-packages/redbot/core/drivers/postgres/postgres.py", line 246, in delete_all_data
await cls._pool.execute(fs.read())
AttributeError: 'NoneType' object has no attribute 'execute'

# Fixed code
async def remove_instance(
    instance,
    interactive: bool = False,
    delete_data: Optional[bool] = None,
    _create_backup: Optional[bool] = None,
    drop_db: Optional[bool] = None,
    remove_datapath: Optional[bool] = None,
):
    data_manager.load_basic_configuration(instance)

    if interactive is True and delete_data is None:
        delete_data = click.confirm(
            "Would you like to delete this instance's data?", default=False
        )

    if interactive is True and _create_backup is None:
        _create_backup = click.confirm(
            "Would you like to make a backup of the data for this instance?",
            default=False,
        )

    if _create_backup is True:
        await create_backup(instance)

    backend = get_current_backend(instance)
    driver_cls = drivers.get_driver_class(backend)
    await driver_cls.initialize(**data_manager.storage_details())
    try:
        if delete_data is True:
            await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)

        if interactive is True and remove_datapath is None:
            remove_datapath = click.confirm(
                "Would you like to delete the instance's entire datapath?",
                default=False,
            )

        if remove_datapath is True:
            data_path = data_manager.core_data_path().parent
            safe_delete(data_path)

        save_config(instance, {}, remove=True)
    finally:
        await driver_cls.teardown()
    print("The instance {} has been removed\n".format(instance))