Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3847

Encoding DatetimeMS objects should use _type_marker system

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.7
    • 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?

      Encoding DatetimeMS objects in the BSON C API should use the _type_marker system. Currently it uses PyObject_TypeCheck which can be a problem in mod_wsgi sub interpreters as described in PYTHON-569: https://github.com/mongodb/mongo-python-driver/blob/79da64a3b186435dc96bea1f0e46eb2966c630eb/bson/_cbsonmodule.c#L863-L868

      https://modwsgi.readthedocs.io/en/latest/user-guides/application-issues.html?highlight=sub%20interpreter#multiple-python-sub-interpreters

      The problematic code:

          } else if (PyObject_TypeCheck(value, (PyTypeObject *) state->DatetimeMS)) {
              long long millis;
              if (!millis_from_datetime_ms(value, &millis)) {
                  return 0;
              }
              *(pymongo_buffer_get_buffer(buffer) + type_byte) = 0x09;
              return buffer_write_int64(buffer, (int64_t)millis);
      

      https://github.com/mongodb/mongo-python-driver/blob/79da64a3b186435dc96bea1f0e46eb2966c630eb/bson/_cbsonmodule.c#L1243-L1249

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: