Skip to content

Commit

Permalink
- Defaulting uuids to uuid4
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Apr 6, 2022
1 parent c47be55 commit 5267b8c
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion geonode/base/migrations/0068_auto_20220403_1334.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 2.2.24 on 2022-04-03 13:34

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):
Expand All @@ -13,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='resourcebase',
name='uuid',
field=models.CharField(max_length=36, unique=True),
field=models.CharField(max_length=36, unique=True, default=str(uuid.uuid4)),
),
]
4 changes: 2 additions & 2 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ class ResourceBase(PolymorphicModel, PermissionLevelMixin, ItemBase):
extra_metadata_help_text = _(
'Additional metadata, must be in format [ {"metadata_key": "metadata_value"}, {"metadata_key": "metadata_value"} ]')
# internal fields
uuid = models.CharField(max_length=36, unique=True)
uuid = models.CharField(max_length=36, unique=True, default=str(uuid.uuid4))
title = models.CharField(_('title'), max_length=255, help_text=_(
'name by which the cited resource is known'))
abstract = models.TextField(
Expand Down Expand Up @@ -2092,7 +2092,7 @@ def resourcebase_post_save(instance, *args, **kwargs):
instance.license = license[0]

if instance.uuid is None or instance.uuid == '':
instance.uuid = str(uuid.uuid1())
instance.uuid = str(uuid.uuid4)

ResourceBase.objects.filter(id=instance.id).update(
thumbnail_url=instance.get_thumbnail_url(),
Expand Down
2 changes: 1 addition & 1 deletion geonode/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def pre_save_document(instance, sender, **kwargs):
instance.extension = urlparse(instance.doc_url).path.rsplit('.')[-1]

if not instance.uuid:
instance.uuid = str(uuid.uuid1())
instance.uuid = str(uuid.uuid4())
instance.csw_type = 'document'

if instance.abstract == '' or instance.abstract is None:
Expand Down
2 changes: 1 addition & 1 deletion geonode/geoserver/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def geoserver_upload(
# Step 8. Create the Django record for the layer
logger.debug('>>> Step 8. Creating Django record for [%s]', name)
alternate = f"{workspace.name}:{gs_resource.name}"
layer_uuid = str(uuid.uuid1())
layer_uuid = str(uuid.uuid4())

defaults = dict(store=gs_resource.store.name,
storeType=gs_resource.store.resource_type,
Expand Down
2 changes: 1 addition & 1 deletion geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def pre_save_layer(instance, sender, **kwargs):
instance.uuid = get_uuid_handler()(instance).create_uuid()
else:
if instance.uuid == '':
instance.uuid = str(uuid.uuid1())
instance.uuid = str(uuid.uuid4())

logger.debug("In pre_save_layer")
if instance.alternate is None:
Expand Down
4 changes: 2 additions & 2 deletions geonode/maps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def update_from_viewer(self, conf, context=None):
self.projection = projection

if self.uuid is None or self.uuid == '':
self.uuid = str(uuid.uuid1())
self.uuid = str(uuid.uuid4())

def source_for(layer):
try:
Expand Down Expand Up @@ -285,7 +285,7 @@ def create_from_layer_list(self, user, layers, title, abstract):
self.center_y = 0

if self.uuid is None or self.uuid == '':
self.uuid = str(uuid.uuid1())
self.uuid = str(uuid.uuid4())

DEFAULT_MAP_CONFIG, DEFAULT_BASE_LAYERS = default_map_config(None)

Expand Down
4 changes: 2 additions & 2 deletions geonode/upload/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def final_step(upload_session, user, charset="UTF-8", layer_id=None):
name=task.layer.name)
if not saved_dataset_filter.exists():
saved_layer = Layer.objects.create(
uuid=layer_uuid or str(uuid.uuid1()),
uuid=layer_uuid or str(uuid.uuid4()),
store=target.name,
storeType=target.store_type,
alternate=alternate,
Expand Down Expand Up @@ -754,7 +754,7 @@ def final_step(upload_session, user, charset="UTF-8", layer_id=None):
name=task.layer.name)
if not saved_dataset_filter.exists():
saved_layer = Layer.objects.create(
uuid=layer_uuid or str(uuid.uuid1()),
uuid=layer_uuid or str(uuid.uuid4()),
store=target.name,
storeType=target.store_type,
alternate=alternate,
Expand Down

0 comments on commit 5267b8c

Please sign in to comment.