Initializing Filepad with URI mode raises InvalidName error

Hello, first off, thank you for this terrific software. I am using it to orchestrate our library’s digitization workflow for OCR, and even though this use case is surely not what y’all had in mind, it is great.

I have this code:

import os
import fireworks
from fireworks import Firework, LaunchPad, ScriptTask
from fireworks.core.rocket_launcher import launch_rocket
import argparse
from fireworks.user_objects.firetasks.filepad_tasks import AddFilesTask
import certifi
from fireworks.utilities.filepad import FilePad
from tqdm import tqdm

parser = argparse.ArgumentParser(prog="Uploader")
parser.add_argument("input_dir")
args = parser.parse_args()
launchpad = fireworks.LaunchPad(
    host=os.getenv("MONGODB_OCR_DEVELOPMENT_CONN_STRING"),
    port=27017,
    uri_mode=True,
    name="fireworks",
    mongoclient_kwargs={
        "tls": True,
        "tlsCAFile": certifi.where(),
    },
)
fp = FilePad(
    host=os.getenv("MONGODB_OCR_DEVELOPMENT_CONN_STRING"),
    port=27017,
    uri_mode=True,
    database="fireworks",
    mongoclient_kwargs={
        "tls": True,
        "tlsCAFile": certifi.where(),
    },
)

I can initialize LaunchPad() completely fine with these arguments. But when FilePad() runs, I receive this error:

Traceback (most recent call last):
  File "/Users/ysc4337/warlock/Impulse/testing.py", line 24, in <module>
    fp = FilePad(
         ^^^^^^^^
  File "/Users/ysc4337/warlock/Impulse/.venv/lib/python3.12/site-packages/fireworks/utilities/filepad.py", line 77, in __init__
    self.db = self.connection[dbname]
              ~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/ysc4337/warlock/Impulse/.venv/lib/python3.12/site-packages/pymongo/synchronous/mongo_client.py", line 1347, in __getitem
__
    return database.Database(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ysc4337/warlock/Impulse/.venv/lib/python3.12/site-packages/pymongo/synchronous/database.py", line 133, in __init__
    _check_name(name)
  File "/Users/ysc4337/warlock/Impulse/.venv/lib/python3.12/site-packages/pymongo/database_shared.py", line 31, in _check_name
    raise InvalidName("database names cannot contain the character %r" % invalid_char)
pymongo.errors.InvalidName: database names cannot contain the character '.'

Comparing the __init__ methods of FilePad and LaunchPad, it seems the logic is different:

filepad.py

        if uri_mode:
            self.connection = MongoClient(host)
            dbname = host.split("/")[-1].split("?")[0]  # parse URI to extract dbname
            self.db = self.connection[dbname]

launchpad.py

        if uri_mode:
            self.connection = MongoClient(host, **self.mongoclient_kwargs)
            if self.name is None:
                raise ValueError("Must specify a database name when using a MongoDB URI string.")
            self.db = self.connection[self.name]

While I do not have a ton of experience using the pymongo API, it seems to me that the FilePad code attempts to parse the database name from the URI string. I think perhaps it should use similar logic to how LaunchPad is initialized, by using self.name instead of trying to parse from the connection string. However I am open to being incorrect here, and if I am please advise on the mistake I made.

Thanks!

Hi - thanks for pointing this out, and really happy to hear about this use case.

I suspect what happened is that MongoDB adjusted its connection protocol at some point, and we updated LaunchPad but forgot to update FilePad because it’s not widely used internally.

Would you like to submit a PR fix to incorporate? This would be preferred since then you will be sure the fix works; however, if not, we can try on our end to make these consistent and push the change. Just let us know what you prefer.

Of course, I can take a stab at it.

In the meantime, if anyone else has problems:

    fp = FilePad(
        host=conn_str + "/fireworks?",
        port=27017,
        uri_mode=True,
        database="fireworks"
)

Does the trick for me.

This has been fixed in pull request 552.

When merged, you will be able to use the same parameters as used in LaunchPad