Skip to content

Commit

Permalink
- Fixes "guardian.exceptions.ObjectNotPersisted: Object None needs to…
Browse files Browse the repository at this point in the history
… be persisted first" exception on "set_workflow_perms" calls
  • Loading branch information
afabiani committed Nov 23, 2020
1 parent 72d59d6 commit dee7de1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
67 changes: 33 additions & 34 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,48 +881,47 @@ def save(self, notify=False, *args, **kwargs):
if hasattr(self, 'class_name') and (self.pk is None or notify):
if self.pk is None and self.title:
# Resource Created

notice_type_label = '%s_created' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True
else:
elif self.pk:
# Resource Updated
_notification_sent = False

super(ResourceBase, self).save(*args, **kwargs)

# Approval Notifications Here
if not _notification_sent and settings.ADMIN_MODERATE_UPLOADS:
if self.is_approved and not self.is_published and \
self.__is_approved != self.is_approved:
# Set "approved" workflow permissions
self.set_workflow_perms(approved=True)

# Send "approved" notification
notice_type_label = '%s_approved' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True

# Publishing Notifications Here
if not _notification_sent and settings.RESOURCE_PUBLISHING:
if self.is_approved and self.is_published and \
self.__is_published != self.is_published:
# Set "published" workflow permissions
self.set_workflow_perms(published=True)

# Send "published" notification
notice_type_label = '%s_published' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True
# Approval Notifications Here
if not _notification_sent and settings.ADMIN_MODERATE_UPLOADS:
if not self.__is_approved and self.is_approved:
# Set "approved" workflow permissions
self.set_workflow_perms(approved=True)

# Send "approved" notification
notice_type_label = '%s_approved' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True

# Publishing Notifications Here
if not _notification_sent and settings.RESOURCE_PUBLISHING:
if not self.__is_published and self.is_published:
# Set "published" workflow permissions
self.set_workflow_perms(published=True)

# Send "published" notification
notice_type_label = '%s_published' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = True

# Updated Notifications Here
if not _notification_sent:
notice_type_label = '%s_updated' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})

# Updated Notifications Here
if not _notification_sent:
notice_type_label = '%s_updated' % self.class_name.lower()
recipients = get_notification_recipients(notice_type_label, resource=self)
send_notification(recipients, notice_type_label, {'resource': self})
_notification_sent = False

super(ResourceBase, self).save(*args, **kwargs)
self.__is_approved = self.is_approved
self.__is_published = self.is_published

Expand Down
8 changes: 7 additions & 1 deletion geonode/geoserver/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ def geoserver_post_save_layers(
"""
Runs update layers.
"""
instance = Layer.objects.get(id=instance_id)
instance = None
try:
instance = Layer.objects.get(id=instance_id)
except Layer.DoesNotExist:
logger.error(f"Layer id {instance_id} does not exist yet!")
return

# Don't run this signal if is a Layer from a remote service
if getattr(instance, "remote_service", None) is not None:
return
Expand Down

0 comments on commit dee7de1

Please sign in to comment.