prologin / concours-site

Source code of the Prologin contest website
https://gitlab.com/prologin/concours/site
GNU General Public License v3.0
10 stars 6 forks source link

"Unknown dates" (value unset) for Event causing issue #300

Closed Nhqml closed 2 years ago

Nhqml commented 3 years ago

Creating an Event without setting the date_begin or the date_end causes problems with the way we compute the phase of the associated Edition.

Should we change the dates fields to mandatory, in which case we would not be able to have "unknown dates" anymore), or should we change the behavior of phase?

Here is a traceback to help reproduce : (only one qualif event defined, no start nor end dates)

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 2.2.17
Python Version: 3.8.6
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'adminsortable',
 'bootstrapform',
 'bootstrap3',
 'captcha',
 'compat',
 'crispy_forms',
 'datatableview',
 'django_bootstrap_breadcrumbs',
 'django_comments',
 'django_prometheus',
 'djmail',
 'hijack',
 'mptt',
 'reversion',
 'rules.apps.AutodiscoverRulesConfig',
 'statictemplate',
 'tagging',
 'prologin',
 'archives',
 'centers',
 'contest',
 'conflose',
 'documents',
 'forum',
 'homepage',
 'qcm',
 'news',
 'pages',
 'problems',
 'schools',
 'sponsor',
 'team',
 'users',
 'django.contrib.admin',
 'massmailer',
 'zinnia',
 'debug_toolbar')
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django_prometheus.middleware.PrometheusBeforeMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'prologin.middleware.ContestMiddleware',
 'django_prometheus.middleware.PrometheusAfterMiddleware')

Traceback:

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in _resolve_lookup
  829.                     current = current[bit]

During handling of the above exception ('Edition' object is not subscriptable), another exception occurred:

File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py" in _get_response
  145.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py" in _get_response
  143.                 response = response.render()

File "/usr/local/lib/python3.8/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/usr/local/lib/python3.8/site-packages/django/template/response.py" in rendered_content
  83.         content = template.render(context, self._request)

File "/usr/local/lib/python3.8/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/usr/local/lib/python3.8/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/usr/local/lib/python3.8/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/loader_tags.py" in render
  188.             return template.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render
  173.                 return self._render(context)

File "/usr/local/lib/python3.8/site-packages/django/test/utils.py" in instrumented_test_render
  96.     return self.nodelist.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/usr/local/lib/python3.8/site-packages/django/template/defaulttags.py" in render
  511.         values = {key: val.resolve(context) for key, val in self.extra_context.items()}

File "/usr/local/lib/python3.8/site-packages/django/template/defaulttags.py" in <dictcomp>
  511.         values = {key: val.resolve(context) for key, val in self.extra_context.items()}

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in resolve
  671.                 obj = self.var.resolve(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in resolve
  796.             value = self._resolve_lookup(context)

File "/usr/local/lib/python3.8/site-packages/django/template/base.py" in _resolve_lookup
  837.                         current = getattr(current, bit)

File "/var/prologin/site/prologin/contest/models.py" in phase
  82.         elif qualif_event and qualif_event.is_finished:

File "/var/prologin/site/prologin/contest/models.py" in is_finished
  129.         return self.date_end < timezone.now()

Exception Type: TypeError at /
Exception Value: '<' not supported between instances of 'NoneType' and 'datetime.datetime'
Elfikurr commented 3 years ago

I believe we could change the start and end dates to mandatory, and we could add a "display" field. When false, we should not display the dates, and display "Unknown".

This would also prevent having to delete (or not create this year) the Finale when we the date is not set.

juli0z commented 2 years ago

Migrated to https://gitlab.com/prologin/concours/site/-/issues/300