diff --git a/osf/models/mixins.py b/osf/models/mixins.py index 1fe75420fa2..d39bd1a19d2 100644 --- a/osf/models/mixins.py +++ b/osf/models/mixins.py @@ -536,6 +536,11 @@ def get_addons(self, service_type: str | None = None, in_request_context: bool = lambda x: x is not None, (self.get_addon(addon) for addon in self.OSF_HOSTED_ADDONS) ) + if not self._id: + # Resources without a guid (e.g. legacy nodes without guids) can't be + # associated with addons in GravyValet, which needs a guid to build + # the resource's semantic IRI. + return osf_addons return itertools.chain(osf_addons, self._get_addons_from_gv(requesting_user_id=user_id, service_type=service_type, auth=auth)) return [_f for _f in [ diff --git a/osf_tests/test_user.py b/osf_tests/test_user.py index 27a447d6681..b1957809d00 100644 --- a/osf_tests/test_user.py +++ b/osf_tests/test_user.py @@ -13,6 +13,7 @@ import itsdangerous import pytest from importlib import import_module +from waffle.testutils import override_flag from framework.auth.exceptions import ExpiredTokenError, InvalidTokenError, ChangePasswordError from framework.auth.signals import user_account_merged @@ -42,6 +43,7 @@ from osf.utils.names import impute_names_model from osf.utils import permissions from osf.exceptions import ValidationError, BlockedEmailError, UserStateError, InstitutionAffiliationStateError +from osf.features import ENABLE_GV from .utils import capture_signals from .factories import ( @@ -2326,6 +2328,16 @@ def test_cant_gdpr_delete_shared_node_if_only_admin(self, user, project_user_is_ assert exc_info.value.args[0] == 'You cannot delete Node {} because it would' \ ' be a Node with contributors, but with no admin.'.format(project_user_is_only_admin._id) + def test_can_gdpr_delete_shared_node_without_guid(self, user, project_with_two_admins): + project_with_two_admins.guids.all().delete() + node = AbstractNode.objects.get(pk=project_with_two_admins.pk) + assert node._id is None + + with override_flag(ENABLE_GV, active=True): + user.gdpr_delete() + + assert user.nodes.all().count() == 0 + def test_cant_gdpr_delete_with_addon_credentials(self, user, project_with_two_admins_and_addon_credentials): with pytest.raises(UserStateError) as exc_info: