From 7e86285887866ed10bc9868a0f9aa3b5e5094aba Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 17 Jul 2022 20:54:28 +0200 Subject: track: don't fail when id is not set This is just debug logging information, but accessing self.id for an object that is not in the database raises an error, because self.id is None and %d cannot format None. In this case, we simply use -1 as id instead. --- fietsboek/models/track.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fietsboek/models/track.py b/fietsboek/models/track.py index 58e9745..1b1c38a 100644 --- a/fietsboek/models/track.py +++ b/fietsboek/models/track.py @@ -275,7 +275,7 @@ class Track(Base): def date(self, value): if value.tzinfo is None: LOGGER.debug('Non-aware datetime passed (track_id=%d, value=%s), assuming offset=0', - self.id, value) + self.id or -1, value) self.date_tz = 0 else: self.date_tz = value.tzinfo.utcoffset(value).total_seconds() // 60 @@ -576,7 +576,7 @@ class TrackCache(Base): def start_time(self, value): if value.tzinfo is None: LOGGER.debug('Non-aware datetime passed (cache_id=%d, value=%s), assuming offset=0', - self.id, value) + self.id or -1, value) self.start_time_tz = 0 else: self.start_time_tz = value.tzinfo.utcoffset(value).total_seconds() // 60 @@ -599,7 +599,7 @@ class TrackCache(Base): def end_time(self, value): if value.tzinfo is None: LOGGER.debug('Non-aware datetime passed (cache_id=%d, value=%s), assuming offset=0', - self.id, value) + self.id or -1, value) self.end_time_tz = 0 else: self.end_time_tz = value.tzinfo.utcoffset(value).total_seconds() // 60 -- cgit v1.2.3