[GODRIVER-2167] Deprecate frequently lossy "bson.RawValue" "AsInt32" and "AsInt32OK" functions Created: 30/Sep/21  Updated: 28/Oct/23  Resolved: 05/Apr/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.12.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Matt Dale
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-632 Add As* methods to bsoncore.Value, bs... Closed
is related to GODRIVER-2751 Make all BSON-to-Go numeric type conv... Backlog
Epic Link: Go Driver 2.0 Prep
Quarter: FY24Q1
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The BSON library currently includes 4 BSON-to-Go numeric value conversion functions that can cause silent data loss:

  • AsInt32/AsInt32OK
  • AsInt64/AsInt64OK

While converting BSON numeric types to a Go int64 can cause data loss in some cases, it's generally for extremely large or extremely small values that most users never encounter (values > 9.2e+18 or < -9.2e+18). However, converting BSON numeric types to a Go int32 can cause data loss for values that users may commonly encounter (values > 2,147,483,647 or < -2,147,483,648). As a result, using AsInt32/AsInt32OK is practically much less safe than AsInt64/AsInt64OK so we should deprecate AsInt32/AsInt32OK and recommend people use AsInt64/AsInt64OK instead. If users really need an int32, they can convert the int64 to an int32 themselves and implement whatever overflow/underflow checking logic they require.

See GODRIVER-2751 for changes to prevent data loss in AsInt64/AsInt64OK.

Definition of done:

  • Deprecate frequently lossy bson.RawValue methods AsInt32 and AsInt32OK.


 Comments   
Comment by Githook User [ 05/Apr/23 ]

Author:

{'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}

Message: GODRIVER-2167 Deprecate frequently lossy AsInt32 and AsInt32OK functions. (#1216)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/30253840006b18c4c35f49b9d06aa971804287bf

Comment by Matt Dale [ 03/Apr/23 ]

PR: https://github.com/mongodb/mongo-go-driver/pull/1216

Generated at Thu Feb 08 08:37:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.