dfo-mar-odis / dart

DFO At-sea Reporting Template, collect Elog, CTD and sample data at sea to produce reports then upload to BioChem at the end of the mission
3 stars 1 forks source link

Mission Filtering is broken #171

Closed upsonp closed 2 weeks ago

upsonp commented 2 weeks ago

Selecting an "After date" or "Before date" on the Mission Filter page causes an unexpected crash.

2024-07-09 10:53:17,269 ERROR    Internal Server Error: /en/mission/view/list/
Traceback (most recent call last):
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\asgiref\sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\django\core\handlers\exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\asgiref\sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\django\core\handlers\base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\asgiref\sync.py", line 468, in __call__
    ret = await asyncio.shield(exec_coro)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\asgiref\current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\DFO-MPO\dart2\dart_env\Lib\site-packages\asgiref\sync.py", line 522, in thread_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\DFO-MPO\dart2\settingsdb\views.py", line 233, in list_missions
    missions = filter_missions(after_date, before_date)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\DFO-MPO\dart2\settingsdb\views.py", line 209, in filter_missions
    if mission.start_date and mission.start_date < after_date:
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'start_date'
upsonp commented 2 weeks ago

The issue is occurring because some databases in my mission database folder didn't have 'start_date' and 'end_date' properties. I have to do a hasattr(mission, 'start_date') check before calling mission.start_date (same for end_date).