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:
Specifically filter away None values (to avoid ending up with an author school dropdown containing a useless "None" as the first entry).
Check whether the value from the database was a list before iterating, and not iterating if it isn't.
Add some basic test coverage of the author tab search view, which wasn't present even before #1907. If that had been present it would have caught this.
I verified that the new test does catch the bug if applied to the old code.
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 aNone
value (because it was a null in the database) and then the server barfed.Here we:
None
values (to avoid ending up with an author school dropdown containing a useless "None" as the first entry).I verified that the new test does catch the bug if applied to the old code.