diff --git a/src/custom_db_backend/base.py b/src/custom_db_backend/base.py new file mode 100644 index 0000000..4789d25 --- /dev/null +++ b/src/custom_db_backend/base.py @@ -0,0 +1,18 @@ +# see https://code.djangoproject.com/ticket/34914#comment:3 +# implemented solution from: https://forum.djangoproject.com/t/django-db-utils-interfaceerror-connection-already-closed-when-updating-from-django-3-0-to-3-1/12708/21 + +import django.db +from django.contrib.gis.db.backends.postgis.base import ( + DatabaseWrapper as BuiltinPostgresDatabaseWrapper, +) +from psycopg2 import InterfaceError + + +class DatabaseWrapper(BuiltinPostgresDatabaseWrapper): + def create_cursor(self, name=None): + try: + return super().create_cursor(name=name) + except InterfaceError: + django.db.close_old_connections() + django.db.connection.connect() + return super().create_cursor(name=name) \ No newline at end of file diff --git a/src/import_export_job/admin.py b/src/import_export_job/admin.py index 7db1181..0f04280 100755 --- a/src/import_export_job/admin.py +++ b/src/import_export_job/admin.py @@ -71,13 +71,13 @@ def __new__(cls, *args, **kwargs): return AdminFormWithUser list_display = ( + "id", "model", "job_status_info", "file_link", "errors", "change_summary_link", "imported", - "owner", "updated_at", ) readonly_fields = ( @@ -85,7 +85,6 @@ def __new__(cls, *args, **kwargs): "change_summary", "imported", "errors", - "owner", "updated_at", "processing_initiated", ) diff --git a/src/import_export_job/tasks.py b/src/import_export_job/tasks.py index 5fb983b..8ab30a3 100755 --- a/src/import_export_job/tasks.py +++ b/src/import_export_job/tasks.py @@ -85,10 +85,16 @@ def update_status(step, message): def run_import_job(pk, dry_run=True): logger.info(f"Importing {pk} dry-run {dry_run}") - import_job = models.ImportJob.objects.get(pk=pk) try: + import_job = models.ImportJob.objects.get(pk=pk) + except Exception as e: + logger.info(f"error op job {pk}: {e}") + return + + try: _run_import_job(import_job, dry_run) except Exception as e: + logger.info(f"error op job {pk}: {e}") import_job.errors += _("Import error %s") % e + "\n" change_job_status(import_job, "import", "Import error", dry_run) import_job.save() diff --git a/src/main/settings.py b/src/main/settings.py index 3be4685..dd41698 100755 --- a/src/main/settings.py +++ b/src/main/settings.py @@ -210,7 +210,7 @@ def resource_temporaldimension(): DATABASES = { "default": { - "ENGINE": "django.contrib.gis.db.backends.postgis", + "ENGINE": "custom_db_backend", "NAME": DATABASE_NAME, "USER": DATABASE_USER, "PASSWORD": DATABASE_PASSWORD, diff --git a/src/statistiek_hub/resources/observation_resource.py b/src/statistiek_hub/resources/observation_resource.py index 16e2e7f..4e64133 100755 --- a/src/statistiek_hub/resources/observation_resource.py +++ b/src/statistiek_hub/resources/observation_resource.py @@ -62,16 +62,10 @@ def clean(self, value, row, **kwargs): start_date = convert_to_date(row["temporal_date"]) end_date = add_timedelta(start_date, temporal_type) - temporal, created = TemporalDimension.objects.get_or_create( + temporal = TemporalDimension.objects.get( type=temporal_type, startdate=start_date, - enddate=end_date, - defaults={ - "name": f"{temporal_type}: {start_date.strftime('%Y-%m-%d')}-->{end_date.strftime('%Y-%m-%d')}", - "type": temporal_type, - "startdate": start_date, - "enddate": end_date, - }, + enddate=end_date ) return temporal