From cf294a9906705f9b7bfb57d4b5745b905697f16f Mon Sep 17 00:00:00 2001 From: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:37:47 +0100 Subject: [PATCH] Database migration to v4.4.x fails with KeyError: 'formats' --- ...2_migrate and_remove_resourcebase_files.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/geonode/base/migrations/0092_migrate and_remove_resourcebase_files.py b/geonode/base/migrations/0092_migrate and_remove_resourcebase_files.py index ea89c795557..76b564cd918 100644 --- a/geonode/base/migrations/0092_migrate and_remove_resourcebase_files.py +++ b/geonode/base/migrations/0092_migrate and_remove_resourcebase_files.py @@ -1,5 +1,4 @@ # Generated by Django 4.2.9 on 2024-03-12 11:55 -import itertools import logging import os @@ -11,7 +10,7 @@ from geonode.base.models import Link from geonode.assets.models import LocalAsset -from geonode.utils import build_absolute_uri, get_supported_datasets_file_types +from geonode.utils import build_absolute_uri logger = logging.getLogger(__name__) @@ -25,9 +24,9 @@ def get_ext(filename): logger.warning(f"Could not find extension for Resource '{res_hm.title}, file '{filename}': {e}") return None - ResourceBase_hm = apps.get_model("base", "ResourceBase") - Dataset_hm = apps.get_model("layers", "Dataset") - Document_hm = apps.get_model("documents", "Document") + ResourceBase_hm = apps.get_model('base', 'ResourceBase') + Dataset_hm = apps.get_model('layers', 'Dataset') + Document_hm = apps.get_model('documents', 'Document') if hasattr(ResourceBase_hm, "files"): # looping on available resources with files to generate the LocalAssets @@ -38,7 +37,12 @@ def get_ext(filename): files = res_hm.files # creating the local asset object - asset = LocalAsset(title="Files", description="Original uploaded files", owner=owner, location=files) + asset = LocalAsset( + title="Files", + description="Original uploaded files", + owner=owner, + location=files + ) asset.save() ### creating the association between asset and Link @@ -56,14 +60,10 @@ def get_ext(filename): ext = get_ext(files[0]) else: ext = None - supported_file_types = get_supported_datasets_file_types() for file in files: - for filetype in supported_file_types: + for filetype in settings.SUPPORTED_DATASET_FILE_TYPES: file_ext = get_ext(file) - _ext = list( - itertools.chain.from_iterable(y for y in [x["required_ext"] for x in filetype["formats"]]) - ) - if file_ext in _ext: + if file_ext in filetype["ext"]: ext = filetype["id"] break if ext: @@ -75,13 +75,14 @@ def get_ext(filename): link_type="uploaded", name="Original upload", extension=ext or "unknown", - url=url, + url=url ) class Migration(migrations.Migration): dependencies = [ + ("base", "0091_create_link_asset_alter_link_type"), ]