From c44a3ad5f917937bd1000aa73a387734b42ad6fc Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sun, 15 Mar 2026 16:59:51 -0500 Subject: [PATCH] Bug Fix: `Stream.last_seen` and `ChannelGroupM3UAccount.last_seen` model defaults now use `django.utils.timezone.now` instead of `datetime.datetime.now`, eliminating spurious `RuntimeWarning: DateTimeField received a naive datetime` warnings emitted during test database creation and on new record creation when `USE_TZ=True`. --- CHANGELOG.md | 1 + .../0005_stream_channel_group_stream_last_seen_and_more.py | 4 ++-- .../0031_channelgroupm3uaccount_is_stale_and_more.py | 4 ++-- apps/channels/models.py | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 232521b3..55afe454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- `Stream.last_seen` and `ChannelGroupM3UAccount.last_seen` model defaults now use `django.utils.timezone.now` instead of `datetime.datetime.now`, eliminating spurious `RuntimeWarning: DateTimeField received a naive datetime` warnings emitted during test database creation and on new record creation when `USE_TZ=True`. - EPG programme parsing crash when an XMLTV source contains programme titles exceeding 255 characters. Previously, a single oversized title would cause the entire `bulk_create` batch to fail with a database truncation error, silently dropping all programmes in that batch. Titles are now truncated to 255 characters before being saved. (Fixes #1039) - Container startup failure when `PUID`/`PGID` is set, caused by `/data/db` ownership conflicts between the `postgres` system user (UID 102) and the configured PUID/PGID. PostgreSQL now runs as the PUID/PGID user in AIO mode, eliminating all `chown`-to-UID-102 operations and unifying `/data` ownership. (Fixes #1078) — Thanks [@CodeBormen](https://github.com/CodeBormen) - Existing installations where PUID/PGID differs from the current `/data/db` owner are migrated automatically on first startup; a sentinel file prevents redundant recursive `chown` on subsequent boots. diff --git a/apps/channels/migrations/0005_stream_channel_group_stream_last_seen_and_more.py b/apps/channels/migrations/0005_stream_channel_group_stream_last_seen_and_more.py index 61a95220..6cbd2622 100644 --- a/apps/channels/migrations/0005_stream_channel_group_stream_last_seen_and_more.py +++ b/apps/channels/migrations/0005_stream_channel_group_stream_last_seen_and_more.py @@ -1,7 +1,7 @@ # Generated by Django 5.1.6 on 2025-03-19 16:33 -import datetime import django.db.models.deletion +import django.utils.timezone import uuid from django.db import migrations, models @@ -22,7 +22,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='stream', name='last_seen', - field=models.DateTimeField(db_index=True, default=datetime.datetime.now), + field=models.DateTimeField(db_index=True, default=django.utils.timezone.now), ), migrations.AlterField( model_name='channel', diff --git a/apps/channels/migrations/0031_channelgroupm3uaccount_is_stale_and_more.py b/apps/channels/migrations/0031_channelgroupm3uaccount_is_stale_and_more.py index 2428a97b..f8246a0b 100644 --- a/apps/channels/migrations/0031_channelgroupm3uaccount_is_stale_and_more.py +++ b/apps/channels/migrations/0031_channelgroupm3uaccount_is_stale_and_more.py @@ -1,6 +1,6 @@ # Generated by Django 5.2.9 on 2026-01-09 18:19 -import datetime +import django.utils.timezone from django.db import migrations, models @@ -19,7 +19,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='channelgroupm3uaccount', name='last_seen', - field=models.DateTimeField(db_index=True, default=datetime.datetime.now, help_text='Last time this group was seen in the M3U source during a refresh'), + field=models.DateTimeField(db_index=True, default=django.utils.timezone.now, help_text='Last time this group was seen in the M3U source during a refresh'), ), migrations.AddField( model_name='stream', diff --git a/apps/channels/models.py b/apps/channels/models.py index 217a92c0..3bebd224 100644 --- a/apps/channels/models.py +++ b/apps/channels/models.py @@ -7,7 +7,7 @@ from apps.proxy.ts_proxy.redis_keys import RedisKeys from apps.proxy.ts_proxy.constants import ChannelMetadataField import logging import uuid -from datetime import datetime +from django.utils import timezone import hashlib import json from apps.epg.models import EPGData @@ -95,7 +95,7 @@ class Stream(models.Model): help_text="Unique hash for this stream from the M3U account", db_index=True, ) - last_seen = models.DateTimeField(db_index=True, default=datetime.now) + last_seen = models.DateTimeField(db_index=True, default=timezone.now) is_stale = models.BooleanField( default=False, db_index=True, @@ -739,7 +739,7 @@ class ChannelGroupM3UAccount(models.Model): help_text='Starting channel number for auto-created channels in this group' ) last_seen = models.DateTimeField( - default=datetime.now, + default=timezone.now, db_index=True, help_text='Last time this group was seen in the M3U source during a refresh' )