[V3 Bank] bank.withdraw/deposit_credits breaks mongodb with floats #1975

Closed
opened 2018-08-03 09:11:39 +02:00 by officiallyemma · 3 comments
officiallyemma commented 2018-08-03 09:11:39 +02:00 (Migrated from github.com)

Other bugs

If you give bank.deposit_credits or bank.withdraw_credit a float instead of an int while using MongoDB, the users balance is stuck as a double. Because of this many cogs break because they expect an int, but get a float.

What were you trying to do?

I was trying to withdraw credits from a users account with

await bank.withdraw_credits(ctx.author, X * 0.30)

although due to a bug I accidentaly ran

await bank.withdraw_credits(ctx.author, X * 0.30)
await bank.deposit_credits(ctx.author, X * 0.30)

This is most likely unrelated to the bug, but I thought I should mention it anyway.

What were you expecting to happen?

I expected red to either throw an error or convert the float to an int

What actually happened?

Red carried on, as if the value was an int. It changed the value type of the balance in mongodb from an int32 to a double. This breaks many other cogs because they expect an int but get a double.

How can we reproduce this issue?

  1. run the following command
await bank.withdraw_credits(ctx.author, X * 0.30)
await bank.deposit_credits(ctx.author, X * 0.30)
  1. done
# Other bugs If you give bank.deposit_credits or bank.withdraw_credit a float instead of an int while using MongoDB, the users balance is stuck as a double. Because of this many cogs break because they expect an int, but get a float. #### What were you trying to do? I was trying to withdraw credits from a users account with `await bank.withdraw_credits(ctx.author, X * 0.30)` although due to a bug I accidentaly ran ``` await bank.withdraw_credits(ctx.author, X * 0.30) await bank.deposit_credits(ctx.author, X * 0.30) ```` This is most likely unrelated to the bug, but I thought I should mention it anyway. #### What were you expecting to happen? I expected red to either throw an error or convert the float to an int #### What actually happened? Red carried on, as if the value was an int. It changed the value type of the balance in mongodb from an int32 to a double. This breaks many other cogs because they expect an int but get a double. #### How can we reproduce this issue? 1. run the following command ``` await bank.withdraw_credits(ctx.author, X * 0.30) await bank.deposit_credits(ctx.author, X * 0.30) ``` 2. done
Tobotimus commented 2018-08-04 07:39:39 +02:00 (Migrated from github.com)

Hi! Thanks for reporting this issue. In my opinion it is best to throw an error when a float is passed to withdraw/deposit_credits, since a float value for credits doesn't really make any sense. We could implicitly convert it to int as you say, but I don't think it's hard for the cog creator to do that instead, and it saves having to account for implicit behaviour.

Hi! Thanks for reporting this issue. In my opinion it is best to throw an error when a float is passed to `withdraw/deposit_credits`, since a float value for credits doesn't really make any sense. We could implicitly convert it to int as you say, but I don't think it's hard for the cog creator to do that instead, and it saves having to account for implicit behaviour.
officiallyemma commented 2018-08-04 19:11:25 +02:00 (Migrated from github.com)

+1 yeah I think throwing an error if the input isn't an int is the way to go.

+1 yeah I think throwing an error if the input isn't an int is the way to go.
Tobotimus commented 2018-08-09 14:14:04 +02:00 (Migrated from github.com)

Resolved by #1976.

Resolved by #1976.
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#1975
No description provided.