openmeteo / enhydris

A database with a web interface for the storage and management of hydro/meteorological measurements and time series
GNU Affero General Public License v3.0
18 stars 11 forks source link

TypeError: '>=' not supported between instances of 'NoneType' and 'Timestamp' #457

Closed aptiko closed 3 years ago

aptiko commented 3 years ago
Internal Server Error: /admin/enhydris/station/1458/change/

TypeError at /admin/enhydris/station/1458/change/
'>=' not supported between instances of 'NoneType' and 'Timestamp'

Request Method: POST
Request URL: https://system.openhi.net/admin/enhydris/station/1458/change/
Django Version: 3.2.4
Python Executable: /opt/enhydris-openhi/venv/bin/python3
Python Version: 3.7.3
Python Path: ['/opt/enhydris-openhi', '/opt/enhydris-openhi', '/opt/enhydris-openhi/venv/bin', '/etc/opt/enhydris/openhi', '/opt/enhydris-openhi/venv/lib/python37.zip', '/opt/enhydris-openhi/venv/lib/python3.7', '/opt/enhydris-openhi/venv/lib/python3.7/lib-dynload', '/usr/lib/python3.7', '/opt/enhydris-openhi/venv/lib/python3.7/site-packages', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages']
Server time: Thu, 24 Jun 2021 15:15:59 +0300
Installed Applications:
['enhydris_openhigis',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.humanize',
 'django.contrib.gis',
 'django.contrib.flatpages',
 'django.contrib.postgres',
 'rest_framework',
 'rest_framework.authtoken',
 'rest_auth',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'rest_auth.registration',
 'rest_captcha',
 'enhydris',
 'enhydris.api',
 'django.contrib.admin',
 'rules.apps.AutodiscoverRulesConfig',
 'parler',
 'nested_admin',
 'enhydris_synoptic',
 'enhydris_autoprocess']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.gzip.GZipMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
 'enhydris_openhigis.middleware.OpenHiGISMiddleware']

Traceback (most recent call last):
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1660, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1587, in _changeform_view
    self.save_related(request, form, formsets, not add)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1127, in save_related
    self.save_formset(request, form, formset, change=change)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1115, in save_formset
    formset.save()
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/nested_admin/formsets.py", line 149, in save
    instance = self.get_saved_instance_for_form(form, commit, form_instances)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/nested_admin/formsets.py", line 235, in get_saved_instance_for_form
    instances = self.save_existing_objects([form], commit)
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/nested_admin/formsets.py", line 364, in save_existing_objects
    saved_instances.append(self.save_existing(form, obj, commit=commit))
  File "/opt/enhydris-openhi/venv/lib/python3.7/site-packages/django/forms/models.py", line 662, in save_existing
    return form.save(commit=commit)
  File "/opt/enhydris-openhi/enhydris/admin/station.py", line 182, in save
    self._save_timeseries_data()
  File "/opt/enhydris-openhi/enhydris/admin/station.py", line 190, in _save_timeseries_data
    self.instance.set_data(data)
  File "/opt/enhydris-openhi/enhydris/models.py", line 779, in set_data
    return self.append_data(data)
  File "/opt/enhydris-openhi/enhydris/models.py", line 783, in append_data
    self._check_new_data_is_newer(ahtimeseries)
  File "/opt/enhydris-openhi/enhydris/models.py", line 792, in _check_new_data_is_newer
    if self.end_date is not None and self.end_date_naive >= new_data_start_date:

Exception Type: TypeError at /admin/enhydris/station/1458/change/
Exception Value: '>=' not supported between instances of 'NoneType' and 'Timestamp'
aptiko commented 3 years ago

I can't reproduce. The code seems right. Other than a race condition, I can't imagine what else could have happened. Closing the issue.