Skip to content

Commit

Permalink
[Fixes #90] Uploaded thumbnail race hazard (#91)
Browse files Browse the repository at this point in the history
(cherry picked from commit 365ac62)
  • Loading branch information
bieganowski authored and afabiani committed Mar 19, 2021
1 parent 95860b5 commit 20da4d1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions mapstore2_adapter/plugins/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ def decode_base64(data):
if is_analytics_enabled:
event_type = EventType.EVENT_CREATE

# Dumps thumbnail from MapStore2 Interface
if _map_thumbnail:
# note: dumping a thumbnail should be performed before update_from_viewer(), to remove
# a race hazard. update_from_viewer() saves an existing map without a thumbnail,
# triggering asynchronous generation of a default thumbnail, which may overwrite uploaded thumb
if _map_thumbnail_format == 'link':
map_obj.thumbnail_url = _map_thumbnail
else:
_map_thumbnail_filename = "map-%s-thumb.%s" % (map_obj.uuid, _map_thumbnail_format)
map_obj.save_thumbnail(_map_thumbnail_filename, _map_thumbnail)

# Update GeoNode Map
_map_conf['map'] = _map_obj
map_obj.update_from_viewer(
Expand All @@ -289,14 +300,6 @@ def decode_base64(data):
if is_analytics_enabled:
register_event(caller.request, event_type, map_obj)

# Dumps thumbnail from MapStore2 Interface
if _map_thumbnail:
if _map_thumbnail_format == 'link':
map_obj.thumbnail_url = _map_thumbnail
else:
_map_thumbnail_filename = "map-%s-thumb.%s" % (map_obj.uuid, _map_thumbnail_format)
map_obj.save_thumbnail(_map_thumbnail_filename, _map_thumbnail)

serializer.validated_data['id'] = map_obj.id
serializer.save(user=caller.request.user)
except Exception as e:
Expand Down

0 comments on commit 20da4d1

Please sign in to comment.