Skip to content
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

Confusing behavior of set_storage vs. MontyClient with memory #80

Open
rkingsbury opened this issue Jun 29, 2023 · 0 comments
Open

Confusing behavior of set_storage vs. MontyClient with memory #80

rkingsbury opened this issue Jun 29, 2023 · 0 comments
Labels
enhancement Things need to improve or adopt

Comments

@rkingsbury
Copy link

rkingsbury commented Jun 29, 2023

To create a memory-mapped DB per the docs I can do

from montydb import set_storage, MontyClient
MontyClient(":memory:")

which results in nothing being written to disk. In the above, ":memory:" is a special repository name.

However if I first use set_storage with ":memory:" as the repository name

set_storage(":memory:")
MontyClient(":memory:")

Then a directory called :memory: is written to the current directory with a monty.storage.cfg file in it, which actually has nothing to do with the created MontyClient.

Similarly, if I pass "memory" as the repository name to MontyClient, a directory called memory is created and the actual underlying storage type is flatfile

>>> mc=MontyClient("memory")
>>> mc
MontyClient(repository='memory', document_class=builtins.dict, storage_engine=MontyStorage(engine: 'FlatFileStorage'))

Finally, if I specify storage="memory" (note the absence of :), with or without a repository,

set_storage(":memory:", storage="memory")
MontyClient(":memory:")

or

set_storage(storage="memory")
MontyClient(":memory:")

then all works as expected and nothing is written to disk.

Strictly speaking none of these are "bugs", but personally I think this behavior is quite confusing and has a risk of unintended behavior. I suggest a few ways to address:

  1. Recognize ":memory:" as a special repo name in set_storage and prevent it from being created as a directory
  2. Warn the user if they pass "memory" as a repository name in MontyClient.__init__(). It is conceivable that someone might want their database to live in a folder called "memory", but I think it's also feasible that a user might pass that argument thinking they were getting a memory database
  3. Expose all the set_storage kwargs in MontyClient.__init__() so that one could say, for example MontyClient(storage='sqlite', use_bson=True) rather than having to understand the nuances of set_storage and invoke it separately.

I'm willing to work on implementing the above, but wanted to hear your feedback first to make sure I'm not misunderstanding some of the intended behavior.

@davidlatwe davidlatwe added the enhancement Things need to improve or adopt label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Things need to improve or adopt
Projects
None yet
Development

No branches or pull requests

2 participants