Skip to content

Commit

Permalink
Merge pull request #10931 from cslzchen/feature/clean-up-sentry-logs
Browse files Browse the repository at this point in the history
[ENG-6990] Clean up Sentry debugging logs
  • Loading branch information
cslzchen authored Jan 20, 2025
2 parents fb705cc + 1db82d7 commit 3b29e35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
14 changes: 6 additions & 8 deletions osf/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,11 @@ def split_guid(cls, guid_str):
return base_guid_str, version

@classmethod
def load(cls, data, select_for_update=False, ignore_not_found=False):
def load(cls, data, select_for_update=False, skip_log_not_found=True):
"""Override load in order to load by Guid.
Update with versioned Guid: if the guid str stored in data is versioned, only the base guid str is used. This
is the expected design because base guid str remains a valid one, and it always refers to the latest version.
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
Expand All @@ -235,19 +233,19 @@ def load(cls, data, select_for_update=False, ignore_not_found=False):
return cls.objects.get(_id=base_guid_str)
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: '
f'[data={data}, guid={base_guid_str}, version={version}]')
if not skip_log_not_found:
logger.debug(f'Object not found from base guid: '
f'[data={data}, base_guid={base_guid_str}, version={version}]')
return None

@classmethod
def load_referent(cls, guid_str, ignore_not_found=False):
def load_referent(cls, guid_str):
"""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)
base_guid_obj = cls.load(base_guid_str)
if not base_guid_obj:
return None, None
# Handles versioned guid str
Expand Down
16 changes: 8 additions & 8 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,16 @@ def create_version(cls, create_from_guid, auth):
raise PermissionsError
unfinished_version, unpublished_version = latest_version.check_unfinished_or_unpublished_version()
if unpublished_version:
sentry.log_message('Failed to create a new version due to unpublished pending version already exists: '
f'[version={unpublished_version.version}, '
f'_id={unpublished_version._id}, '
f'state={unpublished_version.machine_state}].')
logger.error('Failed to create a new version due to unpublished pending version already exists: '
f'[version={unpublished_version.version}, '
f'_id={unpublished_version._id}, '
f'state={unpublished_version.machine_state}].')
raise UnpublishedPendingPreprintVersionExists
if unfinished_version:
sentry.log_message(f'Use existing initiated but unfinished version instead of creating a new one: '
f'[version={unfinished_version.version}, '
f'_id={unfinished_version._id}, '
f'state={unfinished_version.machine_state}].')
logger.warning(f'Use existing initiated but unfinished version instead of creating a new one: '
f'[version={unfinished_version.version}, '
f'_id={unfinished_version._id}, '
f'state={unfinished_version.machine_state}].')
return unfinished_version, None

# Note: version number bumps from the last version number instead of the latest version number
Expand Down
4 changes: 2 additions & 2 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def forgot_password_form():


def resolve_guid_download(guid, provider=None):
resource, _ = Guid.load_referent(guid, ignore_not_found=True)
resource, _ = Guid.load_referent(guid)
if not resource:
raise HTTPError(http_status.HTTP_404_NOT_FOUND)

Expand Down Expand Up @@ -291,7 +291,7 @@ def resolve_guid(guid, suffix=None):
return resolve_guid_download(guid)

# Retrieve resource and version from a guid str
resource, version = Guid.load_referent(guid, ignore_not_found=True)
resource, version = Guid.load_referent(guid)
if not resource or not resource.deep_url:
raise HTTPError(http_status.HTTP_404_NOT_FOUND)

Expand Down

0 comments on commit 3b29e35

Please sign in to comment.