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

Failure releated to compiled lazy import

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.7.2
    • Affects Version/s: 4.7, 4.7.1
    • Component/s: None
    • None
    • Python Drivers
    • 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?

      Detailed steps to reproduce the problem?

      I don't have an easy way to reproduce the issue. I am happy to help test solutions.

      My code works fine when run normally. When I compile my code using Nuitka, then run the resulting executable, I get the following error:

      [root@backend app]# ./api.bin

      Traceback (most recent call last):

        File "/tmp/onefile_7234_1714590961_585141/api.py", line 11, in <module>

          import node_database as node_interface

        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

        File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

        File "/tmp/onefile_7234_1714590961_585141/node_database.py", line 8, in <module node_database>

          from pymongo import MongoClient

        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

        File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

        File "/tmp/onefile_7234_1714590961_585141/pymongo/_init_.py", line 90, in <module pymongo>

        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

        File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

        File "/tmp/onefile_7234_1714590961_585141/pymongo/collection.py", line 43, in <module pymongo.collection>

        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

        File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

        File "/tmp/onefile_7234_1714590961_585141/pymongo/common.py", line 43, in <module pymongo.common>

        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

        File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

        File "/tmp/onefile_7234_1714590961_585141/pymongo/auth.py", line 39, in <module pymongo.auth>

        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

        File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

        File "/tmp/onefile_7234_1714590961_585141/pymongo/auth_aws.py", line 21, in <module pymongo.auth_aws>

        File "/tmp/onefile_7234_1714590961_585141/pymongo/_lazy_import.py", line 31, in lazy_import

      TypeError: exceptions.ModuleNotFoundError does not take keyword arguments

      Definition of done: what must be done to consider the task complete?

      I need to be able to compile my python code and run the resulting binary. It would be nice if everything works in the default configuration. If there is an option to disable lazy_import, that would work, too.

      The exact Python version used, with patch level:

      3.9.18 (main, Jan 24 2024, 00:00:00)

      [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)]

      The exact version of PyMongo used, with patch level:

      The problem does NOT exist in 4.6.3/True.
      The problem does exist in 4.7.0 and 4.7.1
      The file pymongo/_lazy_import.py was added around the time of the 4.7 release. I think the root cause of my problem may be issue PYTHON-4260.

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      Local-only setup.

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      RHEL9

      Web framework or asynchronous network library used, if any, with version (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, ...)

      n/a

      Security Vulnerabilities

      If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            sullivan@assurtech.com stephanie sullivan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: