Properly handle missing schemas/tables in PostgreSQL driver #5855

Merged
Jackenmen merged 8 commits from tests_and_postgresql_driver_improvements into V3/develop 2022-10-13 13:38:43 +02:00
Jackenmen commented 2022-10-01 04:24:25 +02:00 (Migrated from github.com)

Description of the changes

  • Fixes #3983
    • The driver worked as designed however, we've decided that it would be better if we revised this design to avoid executing erroneous SQL queries
    • I've also added additional verification step in the PostgreSQL tests job to make sure we don't suppress any such errors
  • Fixes an edge case in the PostgreSQL driver that could occur when trying to clear the whole Config scope when there's no config data for (cog_name, cog_id) pair:
.tox/postgres/lib/python3.8/site-packages/redbot/core/config.py:386: in clear_raw
    await self.driver.clear(identifier_data)
.tox/postgres/lib/python3.8/site-packages/redbot/core/drivers/postgres/postgres.py:167: in clear
    await self._execute(
.tox/postgres/lib/python3.8/site-packages/redbot/core/drivers/postgres/postgres.py:237: in _execute
    return await method(query, *args)
.tox/postgres/lib/python3.8/site-packages/asyncpg/pool.py:530: in execute
    return await con.execute(query, *args, timeout=timeout)
.tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:317: in execute
    _, status, _ = await self._execute(
.tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:1639: in _execute
    result, _ = await self.__execute(
.tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:1664: in __execute
    return await self._do_execute(
.tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:1711: in _do_execute
    result = await executor(stmt, None)
asyncpg.exceptions.InvalidSchemaNameError: schema "PyTest.32127" does not exist
  • Adds more tests for getting and clearing data on custom config scopes with partial identifiers

Have the changes in this PR been tested?

Yes

Proof that the added tests can fail:
https://github.com/jack1142/Red-DiscordBot/actions/runs/3162818621/jobs/5149778704#step:6:58

### Description of the changes - Fixes #3983 - The driver worked as designed however, we've decided that it would be better if we revised this design to avoid executing erroneous SQL queries - I've also added additional verification step in the PostgreSQL tests job to make sure we don't suppress any such errors - Fixes an edge case in the PostgreSQL driver that could occur when trying to clear the whole Config scope when there's no config data for `(cog_name, cog_id)` pair: ``` .tox/postgres/lib/python3.8/site-packages/redbot/core/config.py:386: in clear_raw await self.driver.clear(identifier_data) .tox/postgres/lib/python3.8/site-packages/redbot/core/drivers/postgres/postgres.py:167: in clear await self._execute( .tox/postgres/lib/python3.8/site-packages/redbot/core/drivers/postgres/postgres.py:237: in _execute return await method(query, *args) .tox/postgres/lib/python3.8/site-packages/asyncpg/pool.py:530: in execute return await con.execute(query, *args, timeout=timeout) .tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:317: in execute _, status, _ = await self._execute( .tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:1639: in _execute result, _ = await self.__execute( .tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:1664: in __execute return await self._do_execute( .tox/postgres/lib/python3.8/site-packages/asyncpg/connection.py:1711: in _do_execute result = await executor(stmt, None) asyncpg.exceptions.InvalidSchemaNameError: schema "PyTest.32127" does not exist ``` - Adds more tests for getting and clearing data on custom config scopes with partial identifiers ### Have the changes in this PR been tested? Yes Proof that the added tests can fail: https://github.com/jack1142/Red-DiscordBot/actions/runs/3162818621/jobs/5149778704#step:6:58
Kowlin (Migrated from github.com) approved these changes 2022-10-13 13:32:54 +02:00
Kowlin (Migrated from github.com) left a comment

Tests are passing, bot runs fine in pSQL from what I've seen, feel free to merge when ready.

Tests are passing, bot runs fine in pSQL from what I've seen, feel free to merge when ready.
red-githubbot[bot] commented 2023-04-19 22:58:13 +02:00 (Migrated from github.com)

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

#6045 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!5855
No description provided.