harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
37 stars 30 forks source link

Correctly handle that institution names are single fields in author index, not arrays #1909

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

PR #1907 modified the casebook search index to allow for the institution (previously affiliation) field to be an array, to represent the case where multiple educators from different institutions contribute to a single casebook.

I neglected to notice that the code to populate the institution dropdown also runs on the Authors tab, and because authors can only belong to one Institution, in the search index it's a string, not an array. If an author doesn't belong to an institution, sensibly the database will represent this as a null.

What was happening is that if someone clicked on the author tab, some code tried to iterate through the value of institution, thinking it was an array, and most often hit a None value (because it was a null in the database) and then the server barfed.

Here we:

I verified that the new test does catch the bug if applied to the old code.