Don't attempt to index users before a Review Board site is fully set up.
Review Request #10700 — Created Sept. 7, 2019 and submitted
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.auth
will prompt the
admin to create a superuser in response to thepost_syncdb
or
post_migrate
signal the first time that theUser
model is added to
the database. This occurs beforedjango.contrib.sites
has a chance to
create itsSite
object. 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
syncdb
command, which never invoked the code that registers our signal
processor. A recent change removed that in favor of directly interfacing
with the Django EvolutionEvolver
class, 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.py
for the first time with a superuser,
and saw that the database populated correctly.