-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: expected str, bytes or os.PathLike object, not int on self._mongod.start() #98
Comments
Thank you so much for the report @stevenmz I'll investigate as soon as possible. |
I'm having the same problem. Issue DescriptionWhen attempting to run 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 Steps to Reproduce
Expected BehaviorThe script should run successfully and create an in-memory mongo instance Additional Information
NOTE: no matter what the settings are in 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. |
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:
The text was updated successfully, but these errors were encountered: