Skip to content

kp_info_cacher inappropriately using local TZ calculations #2677

@saramsey

Description

@saramsey

This code in kp_info_cacher.py is TZ-dependent, right?


        # At this point the KP info caches must NOT be in the process of being
        # refreshed, so we create/update if needed.  In particular, this ensures
        # that the caches will be created/fresh even on dev machines, that don't
        # run the background refresh task.
        one_day_ago = datetime.now() - timedelta(hours=24)

        smart_api_and_meta_map_pathlib_path = pathlib.Path(self.smart_api_and_meta_map_cache)
        try:
            if not smart_api_and_meta_map_pathlib_path.exists():
                raise Exception("KP info cache(s) do not exist.")
            elif (datetime.fromtimestamp(smart_api_and_meta_map_pathlib_path.stat().st_mtime) < one_day_ago):
                raise Exception("KP info cache(s) are older than 24 hours.")
            
        except Exception as e:
            log.error(f"Unable to load KP info caches: {e}")

I kinda think we should be using POSIX time or explicitly UTC, perhaps like this:

import time
from datetime import timedelta

mtime = smart_api_and_meta_map_pathlib_path.stat().st_mtime
if time.time() - mtime > 24 * 3600:
    raise Exception("KP info cache(s) are older than 24 hours.")

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions