long2ice/meilisync

Unable to insert date fields from mysql source

brunoocasali opened this issue · 2 comments

Hi @long2ice, first of all, thanks a lot for this tool. It will be incredibly helpful for everyone. Congratulations on your work!

Before officially starting sharing this tool, I want to ensure everything is working fine, so I'll raise some issues where we can work together to improve it!

So, my table is quite simple:

mysql> SHOW FULL FIELDS FROM authors;
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
| Field      | Type         | Collation          | Null | Key | Default           | Extra             | Privileges                      | Comment |
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+
| id         | int          | NULL               | NO   | PRI | NULL              | auto_increment    | select,insert,update,references |         |
| first_name | varchar(50)  | utf8mb3_unicode_ci | NO   |     | NULL              |                   | select,insert,update,references |         |
| last_name  | varchar(50)  | utf8mb3_unicode_ci | NO   |     | NULL              |                   | select,insert,update,references |         |
| email      | varchar(100) | utf8mb3_unicode_ci | NO   | UNI | NULL              |                   | select,insert,update,references |         |
| birthdate  | date         | NULL               | NO   |     | NULL              |                   | select,insert,update,references |         |
| added      | timestamp    | NULL               | NO   |     | CURRENT_TIMESTAMP | DEFAULT_GENERATED | select,insert,update,references |         |
+------------+--------------+--------------------+------+-----+-------------------+-------------------+---------------------------------+---------+

fake data example:

INSERT INTO `authors` (`id`, `first_name`, `last_name`, `email`, `birthdate`, `added`) VALUES (1, 'Flo', 'Hansen', 'raynor.anika@example.com', '2012-06-07', '1977-01-27 22:00:53');
meilisync-meilisync-1    | TypeError: Object of type date is not JSON serializable
meilisync-meilisync-1    | 2023-04-21 15:32:23.624 | ERROR    | meilisync.main:interval:122 - Error when insert data to MeiliSearch: Object of type date is not JSON serializable

I'm running this MySQL version: 8.0.33 for Linux on aarch64 (MySQL Community Server - GPL).
And the import was not completed. Since there is no way to inform in the configuration file which types the column has, the system should automatically understand it, right?

By the way, I had some weird issues regarding my collation. So I set everything, even the database, to utf8mb4_unicode_ci and it worked fine. I didn't know if it was something caused by my poor-configurated test database.

Yes, maybe we should convert datetime to str before insert into meilisearch