Open stevenmz opened 7 months ago
Thank you so much for the report @stevenmz I'll investigate as soon as possible.
I'm having the same problem.
When attempting to run python3 run_mongo.py
, encountered the following error:
Traceback (most recent call last):
File "/home/almowld/Desktop/penny/official/penny/webhooks/sendgrid/set_mongo.py", line 6, in <module>
client = MongoClient() # No need to provide host
File "/home/almowld/.cache/pypoetry/virtualenvs/app-aYfvlb12-py3.10/lib/python3.10/site-packages/pymongo_inmemory/_pim.py", line 15, in __init__
self._mongod.start()
File "/home/almowld/.cache/pypoetry/virtualenvs/app-aYfvlb12-py3.10/lib/python3.10/site-packages/pymongo_inmemory/mongod.py", line 142, in start
self._proc = subprocess.Popen(boot_command)
File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1796, in _execute_child
self.pid = _posixsubprocess.fork_exec(
TypeError: expected str, bytes or os.PathLike object, not int
setup.cfg
with the following configurations:
[pymongo_inmemory]
mongod_port = 28000
mongo_version=7.0
operating_system=ubuntu
os_version=22
Contents of run_mongo.py
:
from pymongo_inmemory import MongoClient
client = MongoClient() # No need to provide host
db = client['testdb']
collection = db['test-collection']
# etc., etc.
client.close()
python3 run_mongo.py
The script should run successfully and create an in-memory mongo instance
NOTE: no matter what the settings are in setup.cfg
i keep getting the same error. I also tried reverting back to 0.3.1
and it had the same error so I reverted way back to 0.2.11
and it works.
Thank you for your work
I created a PR that should fix this issue. There is an additional PR (#101) that would make this good library useful with MongoDB 7+. While waiting for the maintainers to handle them, I solved the bug by subclassing the MongoClient and Context classes as follows:
from pymongo_inmemory import Mongod, MongoClient
from pymongo_inmemory.context import Context, conf
class MyContext(Context):
def __init__(self, os_name=None, version=None, os_ver=None, ignore_cache=False) -> None:
super(InMemoryContext, self).__init__(os_name, version, os_ver, ignore_cache)
self.storage_engine = conf("storage_engine", "ephemeralForTest")
self.mongod_port = str(self.mongod_port)
class MyMongoClient(MongoClient):
def __init__(self, host=None, port=None, **kwargs):
self._pim_context: Context = MyContext()
if port is not None:
self._pim_context.mongod_port = port
if host is not None:
self._pim_context.mongo_client_host = host
self._mongod = Mongod(self._pim_context)
self._mongod.start()
super(MongoClient, self).__init__(self._mongod.connection_string, **kwargs)
@ekarademir Thank you for latest release - 0.4.1 - which solves this issue. I guess we can close this.
Describe the bug subprocess fails to load mongod on os x
To Reproduce Steps to reproduce the behavior:
Expected behavior MongoClient should connect.
Logs If applicable, add any kind of collected logs to help us understand the problem.
= None, uid = None, umask = -1, start_new_session = False, process_group = -1
Context: