Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AttributeError causing Loan Notification script to fail (PP-997) #1698

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

jonathangreen
Copy link
Member

Description

Make sure we are catching possible AttributeError exceptions and logging them, then continuing with other notifications.

Motivation and Context

It looks like the Loans Notification script is failing for some of our production CM instances with:

{
  "host": "3ca94f118883", 
  "name": "Holds Notification", 
  "level": "ERROR", 
  "filename": "monitor.py", 
  "message": "Error running Holds Notification monitor. Timestamp will not be updated.", 
  "timestamp": "2024-02-26T05:15:17.729003+00:00", 
  "traceback": "Traceback (most recent call last):
  File \"/var/www/circulation/core/monitor.py\", line 187, in run
    new_timestamp = self.run_once(progress)
  File \"/var/www/circulation/core/monitor.py\", line 481, in run_once
    new_offset, batch_size = self.process_batch(offset)
  File \"/var/www/circulation/core/monitor.py\", line 515, in process_batch
    self.process_items(items)
  File \"/var/www/circulation/core/jobs/holds_notification.py\", line 53, in process_items
    self.notifications.send_holds_notifications(items)
  File \"/var/www/circulation/core/util/notifications.py\", line 181, in send_holds_notifications
    f\"hold: {hold.work.title}. Patron has {len(tokens)} device tokens.\"
AttributeError: 'NoneType' object has no attribute 'title'"
}

This is causing us not write the already send notifications out to the DB, which means we try to send them again ... and again .. and again.

How Has This Been Tested?

Running unit tests.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@jonathangreen jonathangreen added the bug Something isn't working label Feb 26, 2024
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 90.08%. Comparing base (20d6e55) to head (2216306).
Report is 1 commits behind head on main.

Files Patch % Lines
core/util/notifications.py 95.45% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1698      +/-   ##
==========================================
- Coverage   90.08%   90.08%   -0.01%     
==========================================
  Files         245      245              
  Lines       28170    28176       +6     
  Branches     6422     6423       +1     
==========================================
+ Hits        25377    25382       +5     
- Misses       1848     1849       +1     
  Partials      945      945              
Flag Coverage Δ
Api 75.78% <0.00%> (-0.02%) ⬇️
Core 59.81% <95.45%> (+<0.01%) ⬆️
migration 26.89% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonathangreen jonathangreen merged commit 67bab4e into main Feb 26, 2024
28 checks passed
@jonathangreen jonathangreen deleted the bugfix/loan-notification-script branch February 26, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants