Giter Site home page Giter Site logo

Comments (11)

jefmud avatar jefmud commented on July 23, 2024 2

from tinymongo.

jefmud avatar jefmud commented on July 23, 2024 1

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.

from tinymongo.

JRileyH avatar JRileyH commented on July 23, 2024 1

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

from tinymongo.

jefmud avatar jefmud commented on July 23, 2024

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

from tinymongo.

davidlatwe avatar davidlatwe commented on July 23, 2024

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

from tinymongo.

jefmud avatar jefmud commented on July 23, 2024

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?

from tinymongo.

lnoest avatar lnoest commented on July 23, 2024

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

from tinymongo.

marcos-diniz avatar marcos-diniz commented on July 23, 2024

I have the same problem using python3.7.5

from tinymongo.

jefmud avatar jefmud commented on July 23, 2024

from tinymongo.

mypolopony avatar mypolopony commented on July 23, 2024

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 :)

from tinymongo.

frankcarey avatar frankcarey commented on July 23, 2024

Still works for me FYI

from tinymongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.