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

Database migration to v4.4.x fails with KeyError: 'formats' #12751

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
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 @@
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 @@

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 @@
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 @@
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