Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error queue #26

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/custom_db_backend/base.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 1 addition & 2 deletions src/import_export_job/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@ 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 = (
"job_status_info",
"change_summary",
"imported",
"errors",
"owner",
"updated_at",
"processing_initiated",
)
Expand Down
8 changes: 7 additions & 1 deletion src/import_export_job/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions src/statistiek_hub/resources/observation_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down