Skip to content

Commit

Permalink
[References GeoNode/geonode#7911] Map payload is not correctly handled
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Dec 17, 2021
1 parent 07e9284 commit e47b883
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions mapstore2_adapter/migrations/0005_map_blob_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@


from django.db import migrations

import json
import logging

logger = logging.getLogger(__name__)

SQL_MIGRATION = '''WITH mapstore_blob AS (
SELECT
msd.resource_id, msd.blob
Expand All @@ -20,6 +21,16 @@
WHERE base_resourcebase.id=subquery.resource_id;
'''

def convert_map_blob(apps, _):
model = apps.get_model('base', 'ResourceBase')
for item in model.objects.filter(resource_type='map'):
if isinstance(item.blob, str):
try:
new_blob = json.loads(item.blob)
model.objects.filter(id=item.id).update(blob=new_blob)
except Exception as e:
logger.exception(e)

class Migration(migrations.Migration):

dependencies = [
Expand All @@ -28,5 +39,6 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunSQL(SQL_MIGRATION)
migrations.RunSQL(SQL_MIGRATION, migrations.RunPython.noop),
migrations.RunPython(convert_map_blob, migrations.RunPython.noop)
]

0 comments on commit e47b883

Please sign in to comment.