Internal
Public Access
Fix task edit crashing after due_date/due_time save (regression from reminders)
The web edit/create/quick-add views and the sync endpoint assigned due_date/due_time/reminder_at straight from request data as raw strings. Django tolerates this at save() (types get coerced deep in the SQL layer), but the in-memory instance keeps the raw strings afterward. Task.reschedule_reminders(), added for per-task reminders and run from save() on that same instance, was the first code to actually operate on those fields before a page reload and crashed with a TypeError - which the service worker's 5xx-treated-as-offline fallback then masked as a misleading "you're offline" screen instead of a real error. Fixed by parsing with Django's parse_date/parse_time/parse_datetime at the point these values are read from the request/payload in tasks/views.py and sync/views.py, rather than trusting raw strings. 5 new regression tests exercise the actual views/endpoint with raw date/time strings and assert proper types land on the model. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
5359bf243a
commit
a27fcc4c69
@@ -133,3 +133,47 @@ class IsOverdueTests(TestCase):
|
||||
mock_now.return_value = django_timezone.make_aware(datetime(2026, 1, 15, 23, 0, 0))
|
||||
task = self.make_task(due_date=date(2026, 1, 1), due_time=dt_time(9, 0, 0), status='completed')
|
||||
self.assertFalse(task.is_overdue)
|
||||
|
||||
|
||||
class WebFormDueDateTypeTests(TestCase):
|
||||
"""
|
||||
The web views assign due_date/due_time straight from request.POST (raw
|
||||
strings), relying on Django to coerce them at the DB layer - which
|
||||
leaves the in-memory instance holding strings after save(). Anything
|
||||
that touches those fields on that same instance afterward (e.g.
|
||||
Task.reschedule_reminders(), called from save() itself) must not choke
|
||||
on that. Regression test for a real production crash on task edit.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_user(
|
||||
username='webformuser', email='webformuser@example.com', password='testpass123',
|
||||
)
|
||||
self.client.force_login(self.user)
|
||||
|
||||
def test_editing_due_date_and_time_does_not_crash(self):
|
||||
task = Task.objects.create(user=self.user, title='Task')
|
||||
response = self.client.post(f'/tasks/{task.id}/', {
|
||||
'title': 'Task', 'status': 'pending', 'priority': 'medium',
|
||||
'due_date': '2026-09-10', 'due_time': '17:00', 'recurrence': 'none',
|
||||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
task.refresh_from_db()
|
||||
self.assertEqual(task.due_date, date(2026, 9, 10))
|
||||
self.assertEqual(task.due_time, dt_time(17, 0))
|
||||
|
||||
def test_creating_task_with_due_date_does_not_crash(self):
|
||||
response = self.client.post('/tasks/new/', {
|
||||
'title': 'New task', 'status': 'pending', 'priority': 'medium',
|
||||
'due_date': '2026-09-10', 'due_time': '17:00', 'recurrence': 'none',
|
||||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
task = Task.objects.get(title='New task')
|
||||
self.assertEqual(task.due_date, date(2026, 9, 10))
|
||||
self.assertEqual(task.due_time, dt_time(17, 0))
|
||||
|
||||
def test_quick_add_task_with_due_date_does_not_crash(self):
|
||||
response = self.client.post('/tasks/quick-add/', {'title': 'Quick task', 'due_date': '2026-09-10'})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
task = Task.objects.get(title='Quick task')
|
||||
self.assertEqual(task.due_date, date(2026, 9, 10))
|
||||
|
||||
Reference in New Issue
Block a user