Fix `BroadcastDayList` to handle all broadcasts on invalid input
The implemented refactoring from #317 (closed) is not working stable. I needed some time to figure out whats happening, but I was not able to find a proper working solution, so needing help here :(
- I was wondering, why I can not open the broadcast list ("Programmplan") again and why I am resulting in an blocking, endless loading. Regardless of language.
- I figured out, that the side tries to load and render all 55.000+ broadcast by enabling SQL debugging and adding a
len()
. I was unable to correct this as enduser and was trapped. - I had also some trouble getting a stable behavior, as it seems that this just appeared on my already logged in browser, not on a new logging in one.
It is a combination of two things
get_context_data()
returns unfiltered broadcasts
1. The following line from the get_context_data
in class BroadcastDayList(FilterView)
seems to not-filter, when the input is not correct. This can be triggered for example by http://localhost:8000/manage/broadcasts/?date=15.11.2022FOO
. The self.filterset.is_valid()
returns false and the full context (containing all broadcasts, as nothing is filtered) is returned. At the end, the page is rendered for a loooong time :)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if not self.filterset.is_valid():
return context
2. Session Handling
I was not knowing about the sessions functionality in the code, now I learned some stuff. But: The session is also storing the wrong date 5.11.2022FOO
without testing and when I come back applying this wrong, so I am not able to leave the cage anymore.
def get(self, request, *args, **kwargs):
if self.request.GET:
self.request.session[SESSION_BROADCAST_DAY_KEY] = self.request.GET
return super().get(request, *args, **kwargs)
Approaches
- Prohibit the return of the full broadcast list hard (as fallback).
- Return the current
datetime.now().date()
if reading of a proper date fromrequest.GET
failed - Validate session data of
SESSION_BROADCAST_DAY_KEY
before usage and clean if validation fails.
Further Aspects
- I was struggeling by implementation attempts in manipulating the queryset. I can overwrite the date inserted to
get_weekday_filter_context()
, but I still get not queryset manipulated to use the current day. I also tried making a redirect, but I was unsure where I should add it. - The SESSION_BROADCAST_DAY_KEY is also used in
program/views/episode.py
, there may be the same problems too?