kaizendorks / pymongo_inmemory

A mongo mocking library with an ephemeral MongoDB running in memory.
MIT License
39 stars 13 forks source link

Bug when using download_url #70

Closed gamemaniaz closed 1 year ago

gamemaniaz commented 1 year ago

Describe the bug If download_url is used instead of derived urls, the following error occurs at line 185 of the following file. https://github.com/kaizendorks/pymongo_inmemory/blob/4f6cdba26253c75690c837025edddfb219a4266a/pymongo_inmemory/downloader/__init__.py#L185

Since download_url returns a single value, it runs into: ValueError: too many values to unpack (expected 2)

To Reproduce Steps to reproduce the behavior:

  1. Command list
import os
from pymongo_inmemory import MongoClient

os.environ["PYMONGOIM__DOWNLOAD_URL"] = "https://somedownloadurl.net"
client = MongoClient()
  1. See error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Programs\mambaforge\lib\site-packages\pymongo_inmemory\_pim.py", line 8, in __init__
    self._mongod = Mongod()
  File "D:\Programs\mambaforge\lib\site-packages\pymongo_inmemory\mongod.py", line 90, in __init__
    self._bin_folder = '' if conf('use_local_mongod') == 'True' else download()
  File "D:\Programs\mambaforge\lib\site-packages\pymongo_inmemory\downloader\__init__.py", line 185, in download
    dl_url, downloaded_version = conf("download_url", best_url(
ValueError: too many values to unpack (expected 2)

Expected behavior For users using download_url, there should be no fallback function, and no variable unpacking is required.

dl_url = conf("download_url")
downloaded_version = "" # will be empty

Context:

ekarademir commented 1 year ago

I've done some explorations. I think while adding that feature, I was expecting download_url to have the same pattern as the ones the library downloads from Mongo servers.

However, I can see that this was a half baked idea. I will need to refactor the download module, which is overdue anyway.

What this means though, this fix will take longer than my original expectation.

ekarademir commented 1 year ago

Hi @gamemaniaz, I just merged a change that should address this. I'll cut a release later today and hopefully it'll fix your problem. If not feel free to re-open this issue.

gamemaniaz commented 1 year ago

Thank you, it works fine now!