MI-DPLA / combine

Combine /kämˌbīn/ - Metadata Aggregator Platform
MIT License
26 stars 11 forks source link

Display of /combine/organization/SomeOrgNum fails when Record Groups have no corresponding Jobs #478

Open fruviad opened 3 years ago

fruviad commented 3 years ago

To repro:

  1. Create a new Organization in Combine
  2. Create three Record Groups for the new Organization. DO NOT create any jobs for these new Record Groups.
  3. Go to the http://servername/combine page. Click on the new Organization's hyperlink. You will see the error:

Sorry! Something went wrong. Please contact your administrator.

<class 'ValueError'> at 2021-02-25 22:50:43.683102+00:00 with args ('max() arg is an empty sequence',): max() arg is an empty sequence

  1. One-by-one, update the Record Groups, adding jobs for them. After adding each job, try to load the page again, and note that it continues to throw the error until ALL of the Record Groups have an associated job.

I tracked this to the /opt/combine-docker/combine/combine/core/models/record_group.py file:

123     @property
124     def last_modified(self):
125         jobs = self.job_set.all()
126         timestamps = [job.timestamp for job in jobs]
127         return max(timestamps)

I changed the above code to:

123     @property
124     def last_modified(self):
125         jobs = self.job_set.all()
126         timestamps = [job.timestamp for job in jobs]
127         try:
128             return max(timestamps)
129         except ValueError:
130             print("failed due to no jobs for record_group")

...and the page stopped throwing an error.

There are doubtless better ways to solve the problem, but that ID's the trigger for it, at least.