From 82be578d91603e47ba50c58066bd97ffb89c5f2e Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Mon, 13 Jan 2025 11:38:50 -0500 Subject: [PATCH] Add None check for guid_str at the very beginning --- osf/models/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osf/models/base.py b/osf/models/base.py index a118f0e1a2b..36d34a4a038 100644 --- a/osf/models/base.py +++ b/osf/models/base.py @@ -227,6 +227,8 @@ def load(cls, data, select_for_update=False, ignore_not_found=False): If `ignore_not_found` is True, then don't log to sentry. This is used in `website.views.resolve_guid()`. """ + if not data: + return None base_guid_str, version = cls.split_guid(data) try: if not select_for_update: @@ -234,13 +236,16 @@ def load(cls, data, select_for_update=False, ignore_not_found=False): return cls.objects.filter(_id=base_guid_str).select_for_update().get() except cls.DoesNotExist: if not ignore_not_found: - sentry.log_message(f'Object not found from base guid: [guid={base_guid_str}, version={version}]') + sentry.log_message(f'Object not found from base guid: ' + f'[data={data}, guid={base_guid_str}, version={version}]') return None @classmethod def load_referent(cls, guid_str, ignore_not_found=False): """Find and return the referent from a given guid str. """ + if not guid_str: + return None, None base_guid_str, version = cls.split_guid(guid_str) base_guid_obj = cls.load(base_guid_str, ignore_not_found=ignore_not_found) if not base_guid_obj: @@ -561,6 +566,8 @@ def load(cls, guid_str, select_for_update=False): base guid str and the version in the guid str. If the guid str does not have version, it returns the object referred by the base guid obj. """ + if not guid_str: + return None try: base_guid_str, version = Guid.split_guid(guid_str) # Version exists