Skip to content

Commit 1e039a6

Browse files
authored
Merge pull request #215 from jackmisner/handle-timezone-aware/naive-datetime-compatability
Handle timezone-aware/naive datetime compatibility in DataVersion doc…
2 parents ed4eb4c + 42eb8c3 commit 1e039a6

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎backend/models/mongo_models.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,13 @@ def is_count_cache_valid(self):
10261026
if not self.last_count_update:
10271027
return False
10281028

1029-
cache_age = (datetime.now(UTC) - self.last_count_update).total_seconds()
1029+
# Handle timezone-aware/naive datetime compatibility
1030+
last_update = self.last_count_update
1031+
if last_update.tzinfo is None:
1032+
# Convert naive datetime to timezone-aware
1033+
last_update = last_update.replace(tzinfo=UTC)
1034+
1035+
cache_age = (datetime.now(UTC) - last_update).total_seconds()
10301036
return cache_age < self.count_cache_ttl
10311037

10321038
def update_count_cache(self, model_class):

0 commit comments

Comments
 (0)