title: Django Celery broken after moving secret key to environment variable
body: <p>I'm working on a Django project that uses Celery for periodic tasks. For improved security, I moved Django's SECRET_KEY into an environment variable. The app ran fine, so Django was certainly able to find the environment variable and set the SECRET_KEY. But an unexpected side effect was that all the regularly occurring Periodic Tasks stopped triggering. I was able to run the tasks manually from Django Admin, so the Celery workers were still alive and well, but the tasks wouldn't trigger themselves like they usually do.</p>
  <p>The app settings and Celery config are both located in a directory called <code>server</code>. Here's the file structure:</p>
  <pre><code>-server
    -__init__.py
    -celery.py
    -settings.py
  </code></pre>
  <p>Before moving the secret key, it was in <code>settings.py</code> like this: <code>SECRET_KEY = &quot;secret&quot;</code></p>
  <p>After moving to an environment variable, the line in <code>settings.py</code> was like this: <code>SECRET_KEY = os.environ.get(&quot;SECRET_KEY&quot;)</code></p>
  <p>And here's the contents of <code>celery.py</code>, in case that's relevant:</p>
  <pre><code>os.environ.setdefault(&quot;DJANGO_SETTINGS_MODULE&quot;, &quot;server.settings&quot;)
  app = Celery(&quot;server&quot;)
  app.config_from_object(&quot;django.conf:settings&quot;, namespace=&quot;CELERY&quot;)
  app.autodiscover_tasks()
  </code></pre>
  <p>As soon as I moved the secret key out of the environment variable and back into <code>settings.py</code>, the tasks started firing again. I'm hoping to figure out why moving the secret key broke the periodic tasks so I can move the secret key back into an environment variable without side effects. Thanks.</p>