populate_db: Use call_consume_in_tests when generating test data.

We'd rather this work be just executed immediately, rather than
queued, since queued events can confuse the queue workers if the
database is dropped and recreated repeatedly.
This commit is contained in:
Tim Abbott 2017-11-21 09:31:05 -08:00
parent 84b9147fe3
commit 708872f361
1 changed files with 8 additions and 0 deletions

View File

@ -478,7 +478,15 @@ def send_messages(data):
saved_data['subject'] = message.subject
message.pub_date = timezone_now()
# We disable USING_RABBITMQ here, so that deferred work is
# executed in do_send_message_messages, rather than being
# queued. This is important, because otherwise, if run-dev.py
# wasn't running when populate_db was run, a developer can end
# up with queued events that reference objects from a previous
# life of the database, which naturally throws exceptions.
settings.USING_RABBITMQ = False
do_send_messages([{'message': message}])
settings.USING_RABBITMQ = True
recipients[num_messages] = (message_type, message.recipient.id, saved_data)
num_messages += 1