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

Codec options tz_aware=True does not work #40

Open
rombr opened this issue Oct 6, 2023 · 0 comments
Open

Codec options tz_aware=True does not work #40

rombr opened this issue Oct 6, 2023 · 0 comments

Comments

@rombr
Copy link

rombr commented Oct 6, 2023

Hi, I need to use CodecOptions(tz_aware=True)

In motor I do this:

from bson.codec_options import CodecOptions
import motor.motor_asyncio

db = motor.motor_asyncio.AsyncIOMotorClient("connection_str")).get_database(
    "db_name",
    codec_options=CodecOptions(tz_aware=True),
)

In mongomock_motor I tried:

from bson.codec_options import CodecOptions
from mongomock_motor import AsyncMongoMockClient

fake_db = AsyncMongoMockClient().get_database(
    "db_name",
    codec_options=CodecOptions(tz_aware=True),
)

But got an error:

lib/python3.11/site-packages/mongomock_motor/__init__.py:242: in get_database
    self.__client.get_database(*args, **kwargs),
lib/python3.11/site-packages/mongomock/mongo_client.py:158: in get_database
    db = self._database_accesses[name] = Database(
lib/python3.11/site-packages/mongomock/database.py:45: in __init__
    mongomock_codec_options.is_supported(codec_options)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

custom_codec_options = CodecOptions(document_class=dict, tz_aware=True, uuid_representation=UuidRepresentation.UNSPECIFIED, unicode_decode_er...ne, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None), datetime_conversion=DatetimeConversion.DATETIME)

    def is_supported(custom_codec_options):
    
        if not custom_codec_options:
            return None
    
>       return CodecOptions(**custom_codec_options._asdict())
E       TypeError: CodecOptions.__new__() got an unexpected keyword argument 'datetime_conversion'

lib/python3.11/site-packages/mongomock/codec_options.py:87: TypeError

Versions:

mongomock-motor==0.0.21
mongomock==4.1.2
pymongo==4.4.1
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

1 participant