Only initialize and teardown driver if actually needed #5313

Merged
leetfin merged 10 commits from V3/develop into V3/develop 2021-09-23 17:34:39 +02:00
leetfin commented 2021-09-12 04:39:15 +02:00 (Migrated from github.com)

Description of the changes

Check if delete_data is True before initializing or tearing down driver.
Closes #5312.

### Description of the changes Check if delete_data is True before initializing or tearing down driver. Closes #5312.
madebylydia commented 2021-09-12 12:03:55 +02:00 (Migrated from github.com)

I think it would be a great idea to let the user know that he should select "No" in case he didn't created the database, otherwise it could be confusing of why it throw an error and doesn't try again with the "No" option. 🤷

I think it would be a great idea to let the user know that he should select "No" in case he didn't created the database, otherwise it could be confusing of why it throw an error and doesn't try again with the "No" option. 🤷
Jackenmen (Migrated from github.com) requested changes 2021-09-12 22:08:57 +02:00
@ -248,39 +248,41 @@ async def remove_instance(
remove_datapath: Optional[bool] = None,
):
data_manager.load_basic_configuration(instance)
backend = get_current_backend(instance)
Jackenmen (Migrated from github.com) commented 2021-09-12 22:06:01 +02:00

This should only be shown when a non-JSON backend is used. Also, you should just say that the removal of instance's data requires the database server to be running as what you currently put is not the only case this can happen.

This should only be shown when a non-JSON backend is used. Also, you should just say that the removal of instance's data requires the database server to be running as what you currently put is not the only case this can happen.
@ -261,1 +261,4 @@
if backend != BackendType.JSON:
msg += " The database server must be running for this to work."
_create_backup = click.confirm(msg, default=False)
Jackenmen (Migrated from github.com) commented 2021-09-12 22:08:53 +02:00

It would be better if all of this were under a single if statement along with try/finally clause:

if delete_data is True:
    try:
        await driver_cls.initialize(**data_manager.storage_details())
        await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
    finally:
        await driver_cls.teardown()
It would be better if all of this were under a single `if` statement along with `try/finally` clause: ```py if delete_data is True: try: await driver_cls.initialize(**data_manager.storage_details()) await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db) finally: await driver_cls.teardown() ```
leetfin (Migrated from github.com) reviewed 2021-09-13 01:08:27 +02:00
@ -261,1 +261,4 @@
if backend != BackendType.JSON:
msg += " The database server must be running for this to work."
_create_backup = click.confirm(msg, default=False)
leetfin (Migrated from github.com) commented 2021-09-13 01:08:27 +02:00

done

done
leetfin (Migrated from github.com) reviewed 2021-09-13 01:10:26 +02:00
@ -248,39 +248,41 @@ async def remove_instance(
remove_datapath: Optional[bool] = None,
):
data_manager.load_basic_configuration(instance)
backend = get_current_backend(instance)
leetfin (Migrated from github.com) commented 2021-09-13 01:10:26 +02:00

Not sure how to check which backend is in use, would I get it from this?
Line 176 default_dirs["STORAGE_TYPE"] = storage_type.value

Not sure how to check which backend is in use, would I get it from this? Line 176 `default_dirs["STORAGE_TYPE"] = storage_type.value`
Jackenmen (Migrated from github.com) reviewed 2021-09-13 01:14:38 +02:00
@ -248,39 +248,41 @@ async def remove_instance(
remove_datapath: Optional[bool] = None,
):
data_manager.load_basic_configuration(instance)
backend = get_current_backend(instance)
Jackenmen (Migrated from github.com) commented 2021-09-13 01:14:38 +02:00

There's a backend = get_current_backend(instance) line a bit below, just move it a bit higher and then you can check it with if backend != BackendType.JSON

There's a `backend = get_current_backend(instance)` line a bit below, just move it a bit higher and then you can check it with `if backend != BackendType.JSON`
leetfin (Migrated from github.com) reviewed 2021-09-13 15:24:55 +02:00
@ -248,39 +248,41 @@ async def remove_instance(
remove_datapath: Optional[bool] = None,
):
data_manager.load_basic_configuration(instance)
backend = get_current_backend(instance)
leetfin (Migrated from github.com) commented 2021-09-13 15:24:55 +02:00

I think I did that right - it's still failing style though. Not sure why

I think I did that right - it's still failing style though. Not sure why
Jackenmen (Migrated from github.com) requested changes 2021-09-14 03:59:23 +02:00
Jackenmen (Migrated from github.com) left a comment

Note: the issues with the Black style should generally be fixed with the Black auto-formatter per our contributing guidelines but in this case, it should be enough to just accept my code suggestions.

Note: the issues with the Black style should generally be fixed with the Black auto-formatter per our contributing guidelines but in this case, it should be enough to just accept my code suggestions.
@ -248,39 +248,41 @@ async def remove_instance(
remove_datapath: Optional[bool] = None,
Jackenmen (Migrated from github.com) commented 2021-09-14 03:53:00 +02:00

There is no need to mention not having the database server, it should be clear enough with just the first part and otherwise, it is also quite long.

                "Would you like to delete this instance's data?"
                " The database server must be running for this to work.",
                default=False,

Also, this code suggestion fixes issues with the black style.

There is no need to mention not having the database server, it should be clear enough with just the first part and otherwise, it is also quite long. ```suggestion "Would you like to delete this instance's data?" " The database server must be running for this to work.", default=False, ``` Also, this code suggestion fixes issues with the black style.
@ -263,4 +266,3 @@
await create_backup(instance)
backend = get_current_backend(instance)
driver_cls = drivers.get_driver_class(backend)
Jackenmen (Migrated from github.com) commented 2021-09-14 03:53:55 +02:00

This and the following lines should not be part of the if delete_date is True block

This and the following lines should not be part of the `if delete_date is True` block
Jackenmen (Migrated from github.com) commented 2021-09-14 03:57:47 +02:00

The code can't have trailing whitespace:

    driver_cls = drivers.get_driver_class(backend)
The code can't have trailing whitespace: ```suggestion driver_cls = drivers.get_driver_class(backend) ```
leetfin commented 2021-09-14 04:59:57 +02:00 (Migrated from github.com)

I think everything is fixed - sorry about all the issues. I probably shouldn't have tried to do this.

I think everything is fixed - sorry about all the issues. I probably shouldn't have tried to do this.
Jackenmen commented 2021-09-14 16:35:20 +02:00 (Migrated from github.com)

I think everything is fixed - sorry about all the issues. I probably shouldn't have tried to do this.

Don't worry, it's your first PR, it can't be perfect :)
It seems all good to me now, I'll test it out later and merge if I don't see any issues with this approach, thanks!

> I think everything is fixed - sorry about all the issues. I probably shouldn't have tried to do this. Don't worry, it's your first PR, it can't be perfect :) It seems all good to me now, I'll test it out later and merge if I don't see any issues with this approach, thanks!
Jackenmen (Migrated from github.com) approved these changes 2021-09-23 17:34:13 +02:00
Jackenmen (Migrated from github.com) left a comment

Looks good to me, thanks for the PR!

Looks good to me, thanks for the PR! ![](https://i.fluffy.cc/7WXqprWzDtCpbfprBZG1Hngnp7H7pfQm.gif)
red-githubbot[bot] commented 2021-09-23 17:34:41 +02:00 (Migrated from github.com)

Thanks L33Tech for the PR 🎉. I'm working now to backport this PR to: 3.4.

Thanks L33Tech for the PR 🎉. I'm working now to backport this PR to: 3.4.
red-githubbot[bot] commented 2021-09-23 17:34:48 +02:00 (Migrated from github.com)

#5333 is a backport of this pull request to Red 3.4.

#5333 is a backport of this pull request to [Red 3.4](https://github.com/Cog-Creators/Red-DiscordBot/tree/3.4).
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!5313
No description provided.