julien-duponchelle/python-mysql-replication

Return timestamp as UTC instead of converting to local timezone

soulee-dev opened this issue · 0 comments

Issue

I recently encountered an issue while testing python-mysql replication, specifically with the test_timestamp. The tests failed due to a discrepancy in handling timestamps.

Details

When a timestamp is inserted into MySQL, the MySQL server converts values from the local timezone to UTC for storage. The replication protocol sends the UTC timestamp, which is in line with the expected behavior.

However, python-mysql-replication appears to convert the timestamp into the local timezone by calling fromtimestamp, leading to unexpected behavior in the tests.

I ran containers with docker-compose, and ran tests on a local Mac system with a time difference of UTC+9 (Korean Standard Timezone), and this seems to be the source of the failure.

Expected Behavior

Considering that this project's philosophy is to parse the replication protocol and pass them to users, I believe it would be more appropriate to return timestamps as UTC, not as the user's local timezone. This change would align with the way MySQL itself handles timestamps, ensuring consistency and predictable behavior.

Potential Impact

I suspect that other projects that interact with this part of the code may be affected as well. If it's deemed necessary, I'm willing to create related issues in those projects.

Solution

I kindly request that you consider modifying the timestamp conversion to return the timestamp as UTC rather than converting it to the local timezone. If desired, I'm willing to assist with a pull request or further discussion to address this issue.

Thank you for your attention to this matter.