Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2167

Deprecate frequently lossy "bson.RawValue" "AsInt32" and "AsInt32OK" functions

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.12.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Not Needed
    • Hide

      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?

      Show
      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?

      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.

            Assignee:
            matt.dale@mongodb.com Matt Dale
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: