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

Error when loading database file #58

Open
lnoest opened this issue May 13, 2020 · 11 comments
Open

Error when loading database file #58

lnoest opened this issue May 13, 2020 · 11 comments

Comments

@lnoest
Copy link

lnoest commented May 13, 2020

When using the example code in Python 3.8 i get this error :

Traceback (most recent call last):
  File "C:/Users/loicn/backend_db.py", line 7, in <module>
    db = connection.my_tiny_database
  File "C:\Users\loicn\AppData\Local\Programs\Python\Python38\lib\site-packages\tinymongo\tinymongo.py", line 73, in __getattr__
    return TinyMongoDatabase(name, self._foldername, self._storage)
  File "C:\Users\loicn\AppData\Local\Programs\Python\Python38\lib\site-packages\tinymongo\tinymongo.py", line 73, in __getattr__
    return TinyMongoDatabase(name, self._foldername, self._storage)
  File "C:\Users\loicn\AppData\Local\Programs\Python\Python38\lib\site-packages\tinymongo\tinymongo.py", line 73, in __getattr__
    return TinyMongoDatabase(name, self._foldername, self._storage)
  [Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded

Process finished with exit code 1
@lnoest lnoest changed the title Error when loading connection in python 3.8 Error when loading database file May 13, 2020
@jefmud
Copy link

jefmud commented May 13, 2020

What version of Python are you running? I am seeing this on Python 3.8.2, but not on Python 3.6.9.

@jefmud
Copy link

jefmud commented May 13, 2020

I figured it out.

TinyDB which TinyMongo wraps around has slightly different behavior in Python 3.8. So there will need to be some changes to TinyMongo to compensate for this.

There is a class "property" from tinydb that is not working in the newest versions of Python. It requires a fix of the class TinyMongoClient() property _storage.

If you want a temporary work-around you can override the class

import tinymongo as tm
import tinydb

class TinyMongoClient(tm.TinyMongoClient):
    @property
    def _storage(self):
        return tinydb.storages.JSONStorage

If you put that code at the top of your module, you can now use TinyMongoClient in the default JSON storage mode.

@davidlatwe
Copy link
Contributor

Maybe you could try the master branch which seems to be TinyDB v4 adopted in this fork: https://github.com/cjboyle/tinymongo

@jefmud
Copy link

jefmud commented May 14, 2020

That fork works, thanks @davidlatwe . I had hacked the module to work. But my version "locked" TinyMongo to the JSONstorage and would not have supported other middlewares. So your version is definitely welcome.

I did not run the suite of tinymongo tests, but the tests in my project associated with its usage of tinymongo passed on all versions of Python 3.5+

    def _storage(self):
        """comments removed"""
        return TinyDB.default_storage_class

Are you guys going to release the fork as a 0.2.1 version?

@lnoest
Copy link
Author

lnoest commented May 14, 2020

What version of Python are you running? I am seeing this on Python 3.8.2, but not on Python 3.6.9.

I was using 3.8.2 but with the workaround it works

@marcos-diniz
Copy link

I have the same problem using python3.7.5

@jefmud
Copy link

jefmud commented May 31, 2020 via email

@mypolopony
Copy link

I actually got this on 3.7.6
The class TinyMongoClient(tm.TinyMongoClient) solution didn't seem to work for me, but I can't 100% ensure that I didn't mess something else up :)

@jefmud
Copy link

jefmud commented Jun 18, 2020 via email

@frankcarey
Copy link

Still works for me FYI

@JRileyH
Copy link

JRileyH commented Nov 14, 2021

How would one support custom serialization such as the DateTimeSerializer provided with tinymongo using this work around?
The suggested method of supporting datetime objects in tinymongo already overrides this property:

import tinydb
from tinydb_serialization import SerializationMiddleware
import tinymongo as tm

class TinyMongoClient(tm.TinyMongoClient):
    @property
    def _storage(self):
        serialization = SerializationMiddleware()
        serialization.register_serializer(tm.serializers.DateTimeSerializer(), 'TinyDate')
        return serialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants