Don't attempt to index users before a Review Board site is fully set up.
Review Request #10700 — Created Sept. 7, 2019 and submitted — Latest diff uploaded
Our Haystack signal processor listens for newly-saved users and, if
search indexing is enabled, adds them to the index. The problem is,
the act of checking if they're enabled (looking up a
SiteConfiguration) can fail when creating a new database with a
superuser for the first time.The reason this happens is that
django.contrib.authwill prompt the
admin to create a superuser in response to thepost_syncdbor
post_migratesignal the first time that theUsermodel is added to
the database. This occurs beforedjango.contrib.siteshas a chance to
create itsSiteobject. Normally that's fine, but our signal processor
is getting in the way by operating on that new superuser and accessing
the not-yet-createdSite.This wasn't a problem in the past because we used to shell out to the
syncdbcommand, which never invoked the code that registers our signal
processor. A recent change removed that in favor of directly interfacing
with the Django EvolutionEvolverclass, meaning that the process is
now taking place in an environment where the signal processor is
registered.This change updates the signal processor to check whether we have the
right entries in the database before handling each signal. This fixes
prepare-dev.py.
Unit tests pass.
Successfully ran
prepare-dev.pyfor the first time with a superuser,
and saw that the database populated correctly.