Skip to content

Removing the requirement to use a task_id #834

Description

@Andrew-S-Rosen

As I discussed with @munrojm, there are instances in maggma where the user has to supply a "task_id" where it is arguably not necessary.

Consider this example:

from maggma.stores import MontyStore

store = MontyStore("my_db")
d = {"test": "hi"}
with store:
    store.update(d)

You get back the following traceback:

--------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[27], line 3
      1 d = {"test": "hi"}
      2 with store:
----> 3     store.update(d)

File [c:\users\asros\github\maggma\src\maggma\stores\mongolike.py:1040](file:///C:/users/asros/github/maggma/src/maggma/stores/mongolike.py:1040), in MontyStore.update(self, docs, key)
   1038     search_doc = {k: d[k] for k in key}
   1039 else:
-> 1040     search_doc = {key: d[key]}
   1042 self._collection.replace_one(search_doc, d, upsert=True)

KeyError: 'task_id'

If the user supplies, say, d = {"task_id": 1, "test": "hi"} it works and you get:

[{'_id': ObjectId('64c2c5e507a03e712c848446'), 'task_id': 1, 'test': 'hi'}]

But this is awkward. If it's already going to assign an _id to the entry, there should not be a need to have the user pass a task_id. If no task_id is specified, it should fallback to using the automatically generated _id.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions