Fix creation of IdentifierData in config raw methods #3829

Merged
Tobotimus merged 7 commits from V3/bugfix/3796 into V3/develop 2020-05-09 07:11:24 +02:00
Tobotimus commented 2020-05-07 12:19:10 +02:00 (Migrated from github.com)

Type

  • Bugfix

Description of the changes

Resolves #3796.

### Type - Bugfix ### Description of the changes Resolves #3796.
tekulvw (Migrated from github.com) reviewed 2020-05-07 12:19:10 +02:00
Twentysix26 (Migrated from github.com) reviewed 2020-05-07 12:19:10 +02:00
Jackenmen (Migrated from github.com) reviewed 2020-05-07 16:26:01 +02:00
Jackenmen (Migrated from github.com) left a comment
No description provided.
Looks good to me, if you want to, we could use some tests for clear/clear_raw on partial pkeys as well but it isn't important enough to block this. Thanks so much for this PR :)
mikeshardmind commented 2020-05-07 18:06:37 +02:00 (Migrated from github.com)

I haven't had a chance to check this myself yet. While at a glance, and based on my memory, it looks like it should, does this handle the case where people used this intentionally to bulk set values with config?

Should there also be a test for this case so that this driver (and future ones, see #3832 #3831 ) continue supporting the same overall usage without extra edge cases that aren't either disallowed or broken?

I haven't had a chance to check this myself yet. While at a glance, and based on my memory, it looks like it should, does this handle the case where people used this intentionally to bulk set values with config? Should there also be a test for this case so that this driver (and future ones, see #3832 #3831 ) continue supporting the same overall usage without extra edge cases that aren't either disallowed or broken?
Tobotimus commented 2020-05-08 05:24:50 +02:00 (Migrated from github.com)

@mikeshardmind, I think those test cases already exist in the PR, unless there are some other ones I'm missing?

@mikeshardmind, I think those test cases already exist in the PR, unless there are some other ones I'm missing?
mikeshardmind commented 2020-05-08 05:45:14 +02:00 (Migrated from github.com)

Unless I'm missing something, all of the test cases in the PR reduce to a singular nested config value. There isn't a test to ensure dicts and subdicts get split properly should the set be caused by a the set which occurs when exiting the context manager over a group. This is something which has been used in cogs, and does work on JSON, and isn't restricted by config (and should work in postgres too IIRC the logic for multiple documents) so it would be good to ensure that this is tested for consistency in the future

Edit: Sorry, I wasn't fully clear on why/what's missing from this, continuing below...

While the test cases here cover all the ways in which the IdentifierData class might exist, the case where this was problematic isn't actually currently covered by a test. none of the tests in config actually check the behavior setting above a group with primary keys not all in the group itself.

Unless I'm missing something, all of the test cases in the PR reduce to a singular nested config value. There isn't a test to ensure dicts and subdicts get split properly should the set be caused by a the set which occurs when exiting the context manager over a group. This is something which has been used in cogs, and does work on JSON, and isn't restricted by config (and should work in postgres too IIRC the logic for multiple documents) so it would be good to ensure that this is tested for consistency in the future Edit: Sorry, I wasn't fully clear on why/what's missing from this, continuing below... While the test cases here cover all the ways in which the IdentifierData class might exist, the case where this was problematic isn't actually currently covered by a test. none of the tests in config actually check the behavior setting above a group with primary keys not all in the group itself.
Jackenmen commented 2020-05-08 12:50:16 +02:00 (Migrated from github.com)

Edit: Sorry, I wasn't fully clear on why/what's missing from this, continuing below...

While the test cases here cover all the ways in which the IdentifierData class might exist, the case where this was problematic isn't actually currently covered by a test. none of the tests in config actually check the behavior setting above a group with primary keys not all in the group itself.

So you're thinking of a test for wrong input? e.g.

config.init_custom("TEST", 3)
await config.custom("TEST").set({"1": {"foo": "bar"}}) # incomplete primary keys - only 1
> Edit: Sorry, I wasn't fully clear on why/what's missing from this, continuing below... > > While the test cases here cover all the ways in which the IdentifierData class might exist, the case where this was problematic isn't actually currently covered by a test. none of the tests in config actually check the behavior setting above a group with primary keys not all in the group itself. So you're thinking of a test for wrong input? e.g. ```py config.init_custom("TEST", 3) await config.custom("TEST").set({"1": {"foo": "bar"}}) # incomplete primary keys - only 1 ```
mikeshardmind commented 2020-05-08 16:56:57 +02:00 (Migrated from github.com)

No, sorry, I mean that because the JSON driver and other drivers are going to deal with groups fundamentally differently, the fact that none of the config tests make any attempt at setting above a "normal" group leaves room for surprises in the differences between the drivers.

Here's an example of something which should either be guaranteed to work across all drivers, or be disallowed, but that there is no test for.

config.init_custom("TEST", 1)
await config.custom("TEST").set(
    {"identifier_one": {"some_valname" : 1}, "identifier_two": {"some_valname": 1}}
)

Notice that in this case, there should actually be 2 instances of identifer data and values
It would be easy to assume this should require 2 seperate set operations with 2 different instances of identifier data, however, this can happen relatively naturally since config.custom is documented as returning a config group, and config groups are documented as being able to be used as a context manager to modify all values within. So this somewhat unnatural looking set would be the resulting call from __aexit__ in the below.

config.init_custom("TEST", 1)

group = config.custom("TEST")
async with group() as test_data:
    for identifier in ("identifier_one", "identifier_two"):
        test_data[identifier] = {"some_valname": 1}

All of this is technically within what config supports as documented, and the JSON driver handles this with zero surprises, though this is more a consequence of the JSON driver not making a distinction between config groups and values which are dicts, as was already brought up before.

If there's going to be more drivers added, the behavior of this should probably be ensured to be uniform across all of them.

No, sorry, I mean that because the JSON driver and other drivers are going to deal with groups fundamentally differently, the fact that none of the config tests make any attempt at setting above a "normal" group leaves room for surprises in the differences between the drivers. Here's an example of something which should either be guaranteed to work across all drivers, or be disallowed, but that there is no test for. ```py config.init_custom("TEST", 1) await config.custom("TEST").set( {"identifier_one": {"some_valname" : 1}, "identifier_two": {"some_valname": 1}} ) ``` ~~Notice that in this case, there should actually be 2 instances of identifer data and values~~ It would be easy to assume this should require 2 seperate set operations with 2 different instances of identifier data, however, this can happen relatively naturally since config.custom is documented as returning a config group, and config groups are documented as being able to be used as a context manager to modify all values within. So this somewhat unnatural looking set would be the resulting call from `__aexit__` in the below. ```py config.init_custom("TEST", 1) group = config.custom("TEST") async with group() as test_data: for identifier in ("identifier_one", "identifier_two"): test_data[identifier] = {"some_valname": 1} ``` All of this is technically within what config supports as documented, and the JSON driver handles this with zero surprises, though this is more a consequence of the JSON driver not making a distinction between config groups and values which are dicts, as was already brought up before. If there's going to be more drivers added, the behavior of this should probably be ensured to be uniform across all of them.
Tobotimus commented 2020-05-08 22:47:12 +02:00 (Migrated from github.com)

@mikeshardmind thanks for bringing that up, I'll add a test for that today.

This usage was in fact always supported, we just never had a test for it and thus the bug in config never surfaced until later. The postgres driver supports it still as a single set() operation and a single INSERT query which inserts many rows

@mikeshardmind thanks for bringing that up, I'll add a test for that today. This usage was in fact always supported, we just never had a test for it and thus the bug in config never surfaced until later. The postgres driver supports it still as a single set() operation and a single INSERT query which inserts many rows
Tobotimus commented 2020-05-09 03:02:38 +02:00 (Migrated from github.com)

Tests added

Tests added
Jackenmen (Migrated from github.com) approved these changes 2020-05-09 04:07:15 +02:00
Jackenmen (Migrated from github.com) left a comment

Looks good to me, we will have to look into our tests for Config more before pursuing all the new drivers but this PR contains the needed tests for the stuff it's supposed takes care of.

Looks good to me, we will have to look into our tests for Config more before pursuing all the new drivers but this PR contains the needed tests for the stuff it's supposed takes care of.
Sign in to join this conversation.
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!3829
No description provided.