long2ice / meilisync

Realtime sync data from MySQL/PostgreSQL/MongoDB to Meilisearch
https://github.com/long2ice/meilisync
Apache License 2.0
247 stars 37 forks source link

Not support datetime Type #31

Open PittyXu opened 9 months ago

PittyXu commented 9 months ago

mysql sync error

TypeError: Object of type datetime is not JSON serializable

kyp76 commented 9 months ago

Hello I have the same issue

meilisync  | │ │               │   │   'XUserAccountId': 10,                              │ │
meilisync  | │ │               │   │   'DisabledDate': None,                              │ │
meilisync  | │ │               │   │   'EnabledDate': datetime.datetime(2019, 3, 4, 18,   │ │
meilisync  | │ │               43, 33),                                                   │ │
meilisync  | │ │               │   │   'AccessType': 2,                                   │ │
meilisync  | │ │               │   │   'AccountId': 15583,                                │ │
meilisync  | │ │               │   │   'UserId': 3869,                                    │ │
meilisync  | │ │               │   │   'DisabledById': None,                              │ │
meilisync  | │ │               │   │   'EnabledById': 2093                                │ │
meilisync  | │ │               │   },                                                     │ │
meilisync  | │ │               │   ... +990                                               │ │
meilisync  | │ │               ]                                                          │ │
meilisync  | │ │        self = <json.encoder.JSONEncoder object at 0x7ffffe91a2e0>        │ │
meilisync  | │ ╰──────────────────────────────────────────────────────────────────────────╯ │
meilisync  | │                                                                              │
meilisync  | │ /usr/local/lib/python3.9/json/encoder.py:179 in default                      │
meilisync  | │                                                                              │
meilisync  | │   176 │   │   │   │   return JSONEncoder.default(self, o)                    │
meilisync  | │   177 │   │                                                                  │
meilisync  | │   178 │   │   """                                                            │
meilisync  | │ ❱ 179 │   │   raise TypeError(f'Object of type {o.__class__.__name__} '      │
meilisync  | │   180 │   │   │   │   │   │   f'is not JSON serializable')                   │
meilisync  | │   181 │                                                                      │
meilisync  | │   182 │   def encode(self, o):                                               │
meilisync  | │                                                                              │
meilisync  | │ ╭────────────────────────── locals ──────────────────────────╮               │
meilisync  | │ │    o = datetime.datetime(2019, 2, 28, 22, 33, 54)          │               │
meilisync  | │ │ self = <json.encoder.JSONEncoder object at 0x7ffffe91a2e0> │               │
meilisync  | │ ╰────────────────────────────────────────────────────────────╯               │
meilisync  | ╰──────────────────────────────────────────────────────────────────────────────╯
meilisync  | TypeError: Object of type datetime is not JSON serializable

could you do fix this issue ASAP ?

Thank you

long2ice commented 9 months ago

What about try latest code

kyp76 commented 9 months ago

Hello I did a test with the latest version of our dev branch, I do not have the same error but I have a new one ==>

`meilisync  | │ │         │   {'EnabledDate': datetime.datetime(2019, 3, 4, 18, 43, 33)},  │ │
meilisync  | │ │         │   {'EnabledDate': datetime.datetime(2019, 3, 4, 18, 43, 33)},  │ │
meilisync  | │ │         │   {'EnabledDate': datetime.datetime(2019, 3, 4, 18, 43, 33)},  │ │
meilisync  | │ │         │   {'EnabledDate': datetime.datetime(2019, 3, 4, 18, 43, 33)},  │ │
meilisync  | │ │         │   ... +990                                                     │ │
meilisync  | │ │         ]                                                                │ │
meilisync  | │ │  self = <meilisync.meili.Meili object at 0x7ffffab23710>                 │ │
meilisync  | │ │  sync = Sync(                                                            │ │
meilisync  | │ │         │   plugins=[],                                                  │ │
meilisync  | │ │         │   table='xuseraccount',                                        │ │
meilisync  | │ │         │   pk='XUserAccountId',                                         │ │
meilisync  | │ │         │   full=True,                                                   │ │
meilisync  | │ │         │   index='xuseraccount',                                        │ │
meilisync  | │ │         │   fields={'EnabledDate': None}                                 │ │
meilisync  | │ │         )                                                                │ │
meilisync  | │ │ tasks = []                                                               │ │
meilisync  | │ ╰──────────────────────────────────────────────────────────────────────────╯ │
meilisync  | ╰──────────────────────────────────────────────────────────────────────────────╯
meilisync  | TypeError: 'async for' requires an object with __aiter__ method, got list`

could you tell me why ?? @long2ice

And also on the config.yml following parameters (index/fileds and sentry) are now mandatory, it s not coherent with your documentation (https://github.com/long2ice/meilisync/blob/dev/README.md?plain=1#L201).

long2ice commented 9 months ago

Fixed settings optional and try latest code. Also please show full stack.

ThangBuiDuc commented 9 months ago

I have same issue with docker container. Has this been fixed yet?

markusthegeek commented 9 months ago

@long2ice I got the same error as above when using your default MongoDB config with Full set to true, it works fine with Full set to false. Can you reproduce this? I tested with your latest code from Github. Error seems gone once the index is created in Meilisearch via Full set to false and then switching back to true but still no full sync happens...

The incremental sync works great with MongoDB and seems super fast :-D

https://github.com/long2ice/meilisync/blob/dev/tests/config/mongo.yml

C:\Users\marku\AppData\Local\Programs\Python\Python312\Lib\site-packages\meilisync\meili.py:33   │
│ in add_full_data                                                                                 │
│                                                                                                  │
│    30 │   async def add_full_data(self, sync: Sync, data: AsyncGenerator):                       │
│    31 │   │   tasks = []                                                                         │
│    32 │   │   count = 0                                                                          │
│ >  33 │   │   async for items in data:                                                           │
│    34 │   │   │   count += len(items)                                                            │
│    35 │   │   │   events = [Event(type=EventType.create, data=item) for item in items]           │
│    36 │   │   │   task = await self.handle_events_by_type(sync, events, EventType.create)

TypeError: 'async for' requires an object with __aiter__ method, got list