Kaggle / Kaggle/kagglehub

AttributeError: datetime.UTC crash in cached download freshness check (all platforms)

Open Beginner friendly
#314 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
529
Forks
165
PR merge metrics
No merged PRs in 30d

Description

## Bug

`src/kagglehub/clients.py` imports the `datetime` **class** but references `datetime.UTC`:

```python
from datetime import datetime
...
remote_date = datetime.strptime(response.headers["Last-Modified"], ...).replace(tzinfo=datetime.UTC)
local_date = datetime.fromtimestamp(os.path.getmtime(cached_path), tz=datetime.UTC)
```

`UTC` exists only as a **module-level** alias (`datetime.UTC`, Python 3.11+) — it does not exist on the `datetime` class in any Python version. The comparison therefore always raises:

```
AttributeError: type object 'datetime.datetime' has no attribute 'UTC'
```

## Repro

`competition_download` with a cached archive and a server `Last-Modified` header (covered by `tests/test_http_competition_download.py::test_competition_download_ignored_cache_when_lastest_is_newer`, which fails on `main` on every platform).

## Fix

Replace `datetime.UTC` with `timezone.utc` (PR incoming).

Contributor guide

Open the contributing guide

Research direction

Start in src/kagglehub/clients.py and inspect the datetime imports and cached download freshness comparison. Run tests/test_http_competition_download.py::test_competition_download_ignored_cache_when_lastest_is_newer to reproduce the failure. Done means the test passes and cached archives are compared against the Last-Modified header without an AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
90/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.