Skip to content

Commit

Permalink
Database migration to v4.4.x fails with KeyError: 'formats'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi authored Nov 27, 2024
1 parent 27476dc commit cf294a9
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generated by Django 4.2.9 on 2024-03-12 11:55
import itertools
import logging
import os

Expand All @@ -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__)

Expand All @@ -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
Expand All @@ -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(

Check warning on line 40 in geonode/base/migrations/0092_migrate and_remove_resourcebase_files.py

View check run for this annotation

Codecov / codecov/patch

geonode/base/migrations/0092_migrate and_remove_resourcebase_files.py#L40

Added line #L40 was not covered by tests
title="Files",
description="Original uploaded files",
owner=owner,
location=files
)
asset.save()

### creating the association between asset and Link
Expand All @@ -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:
Expand All @@ -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"),
]

Expand Down

0 comments on commit cf294a9

Please sign in to comment.