Skip to content

Commit e79cd6c

Browse files
committed
Release 4.0.3: Bug fix for TypeError in Telegram backend
After fixing this bug I realized that pull request #2 fixes the same bug as well, although in a slightly different way: #2 In case anyone is wondering: I'm only just now looking through this pull request, not yet sure what to do with the rest of the suggested changes.
1 parent 813bb22 commit e79cd6c

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

CHANGELOG.rst

+28
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ to `semantic versioning`_.
1111
.. _Keep a Changelog: http://keepachangelog.com/
1212
.. _semantic versioning: http://semver.org/
1313

14+
`Release 4.0.3`_ (2020-03-27)
15+
-----------------------------
16+
17+
Bug fix for the following :exc:`~exceptions.TypeError` exception raised by the Telegram backend:
18+
19+
.. code-block:: python
20+
21+
Traceback (most recent call last):
22+
File "../lib/python3.5/site-packages/chat_archive/cli.py", line 199, in main
23+
command_fn(arguments)
24+
File "../lib/python3.5/site-packages/chat_archive/cli.py", line 286, in sync_cmd
25+
self.synchronize(*arguments)
26+
File "../lib/python3.5/site-packages/chat_archive/__init__.py", line 335, in synchronize
27+
self.initialize_backend(backend_name, account_name).synchronize()
28+
File "../lib/python3.5/site-packages/chat_archive/backends/telegram.py", line 97, in synchronize
29+
event_loop.run_until_complete(self.connect_then_sync())
30+
File "/usr/lib/python3.5/asyncio/base_events.py", line 467, in run_until_complete
31+
return future.result()
32+
File "/usr/lib/python3.5/asyncio/futures.py", line 294, in result
33+
raise self._exception
34+
File "/usr/lib/python3.5/asyncio/tasks.py", line 240, in _step
35+
result = coro.send(None)
36+
File "../lib/python3.5/site-packages/chat_archive/backends/telegram.py", line 124, in connect_then_sync
37+
elif dialog.date > conversation_in_db.last_modified:
38+
TypeError: can't compare offset-naive and offset-aware datetimes
39+
40+
.. _Release 4.0.3: https://github.com/xolox/python-chat-archive/compare/4.0.2...4.0.3
41+
1442
`Release 4.0.2`_ (2018-12-31)
1543
-----------------------------
1644

chat_archive/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Easy to use offline chat archive.
22
#
33
# Author: Peter Odding <[email protected]>
4-
# Last Change: December 31, 2018
4+
# Last Change: March 27, 2020
55
# URL: https://github.com/xolox/python-chat-archive
66

77
"""Python API for the `chat-archive` program."""
@@ -29,7 +29,7 @@
2929
"""The name of the default account (a string)."""
3030

3131
# Semi-standard package versioning.
32-
__version__ = "4.0.2"
32+
__version__ = "4.0.3"
3333

3434
# Initialize a logger for this module.
3535
logger = VerboseLogger(__name__)

chat_archive/backends/telegram.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Easy to use offline chat archive.
22
#
33
# Author: Peter Odding <[email protected]>
4-
# Last Change: August 1, 2018
4+
# Last Change: March 27, 2020
55
# URL: https://github.com/xolox/python-chat-archive
66

77
"""
@@ -25,7 +25,7 @@
2525
# Modules included in our package.
2626
from chat_archive.backends import ChatArchiveBackend
2727
from chat_archive.models import Account, Conversation
28-
from chat_archive.utils import ensure_directory_exists, get_secret
28+
from chat_archive.utils import ensure_directory_exists, get_secret, strip_tzinfo
2929

3030
FRIENDLY_NAME = "Telegram"
3131
"""A user friendly name for the chat service supported by this backend (a string)."""
@@ -121,7 +121,7 @@ async def connect_then_sync(self):
121121
)
122122
if not conversation_in_db.import_complete:
123123
await self.perform_initial_sync(dialog, conversation_in_db)
124-
elif dialog.date > conversation_in_db.last_modified:
124+
elif strip_tzinfo(dialog.date) > strip_tzinfo(conversation_in_db.last_modified):
125125
logger.info("Conversation was updated (%s) ..", dialog.id)
126126
await self.update_conversation(dialog, conversation_in_db)
127127
conversation_in_db.last_modified = dialog.date

chat_archive/utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Easy to use offline chat archive.
22
#
33
# Author: Peter Odding <[email protected]>
4-
# Last Change: August 1, 2018
4+
# Last Change: March 27, 2020
55
# URL: https://github.com/xolox/python-chat-archive
66

77
"""Utility functions for the `chat-archive` program."""
@@ -98,6 +98,11 @@ def prompt_for_password(prompt_text):
9898
return getpass.getpass(prompt_text)
9999

100100

101+
def strip_tzinfo(value):
102+
"""Strip timezone information from :class:`datetime.datetime` objects to enable comparison."""
103+
return value if value.tzinfo is None else value.replace(tzinfo=None)
104+
105+
101106
def utc_to_local(utc_value):
102107
"""Convert a UTC :class:`~datetime.datetime` object to the local timezone."""
103108
epoch = time.mktime(utc_value.timetuple())

0 commit comments

Comments
 (0)