Answers.Body: <p>I have one Drupal 9 site with this problem, and several more that don't. I don't know the root cause of the issue, but I know that adding <code>--level=cms-full</code> to the <code>cv</code> command fixes the issue.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-25T20:24:12.157Z
Answers.LastActivityDate: 2023-08-25T20:24:12.157Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>So, if your civicrm system jobs are all running, then the question is about where the extra Drupal error email is coming from (regardless of whether it gets emailed to you or just displayed on the command line when you don't use --quiet).</p>
  <p>The success of the manual run suggests one of your system jobs is generating that message but not quitting in any fatal way.</p>
  <p>I'd recommend that you look through your individual system jobs that run with each cron and run them individually via the web interface and see if they give you any clues.</p>
  <p>If that doesn't help, or if you're happy enough on the command line, you can just run them each via the command line (the civicrm system cron is just a way of selecting and running individual system jobs).</p>
  <p>I'd guess it's coming from an older extension that doesn't play well with modern Drupal, or a Drupal module that's implementing a civicrm system job.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-25T15:22:56.313Z
Answers.LastActivityDate: 2023-08-25T15:22:56.313Z
Answers.UserDisplayName: Alan Dixon
Answers.Body: <p>Two thoughts:</p>
  <ul>
  <li>Check the version of <code>cv</code>.</li>
  <li>I don't use the <code>cwd</code> option so maybe it does something different for boot ordering, and I notice <code>sites/default/web</code> is an odd path but you might just have typed that as an example. If that is the right path and it's maybe the use of <code>cwd</code>, then an alternate is change your task to be <code>cd /home/xx/whatever; /usr/local/bin/cv api3 ...etc...</code></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-22T09:18:15.883Z
Answers.Text: Thanks. ```cv``` version reports as v0.3.46
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-22T09:42:53.110Z
Answers.Text: As I understand it ```cwd``` is simply used to specify the root directory (where Drupal's index.php file sits) of the site where I want the api call to be made. Maybe I should be more specific and set ```cwd``` to the path to civicrm, or cron.php?
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-21T22:19:56.883Z
Answers.LastActivityDate: 2023-08-21T22:19:56.883Z
Answers.UserDisplayName: Demerit
Body: <p>I have a D9/Civi site and the main Civi cron is set up to run every 5 minutes using <code>cv</code> :</p>
  <p><code>/usr/local/bin/cv api job.execute --user=xxx --cwd=/home/xx/sites/default/web --quiet</code></p>
  <p>The cron job runs, but I get an email every time which reports:</p>
  <pre><code>In Drupal.php line 179:
  
   \Drupal::$container is not initialized yet. \Drupal::setContainer() must be  
    called with a real container.                                               
  </code></pre>
  <p>How can I stop this from happening? Is it do with the permissions of the selected user?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-22T19:43:54.230Z
Comments.Text: When you say "the cron job runs" are you saying that some or all of the corresponding civicrm system jobs run? If that's the case, then it's likely just one of your system jobs that is generating that message and failing.
Comments.UserDisplayName: Alan Dixon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-22T19:44:28.517Z
Comments.Text: What happens when you run the cron job manually (as whatever user your cron is running as, without the --quiet)?
Comments.UserDisplayName: Alan Dixon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-24T16:40:33.267Z
Comments.Text: If I run the job manually from the command line using cv and without the --quiet, I get back: ```{
      "is_error": 0,
      "version": 3,
      "count": 1,
      "values": 1
  }```
Comments.UserDisplayName: Graham
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-25T06:13:39.363Z
Comments.Text: So, if I remove the ```--quiet``` parameter from the crontab I get an email with the above information. Adding it back in and I get an email with the note about $container not bneing initialized.
Comments.UserDisplayName: Graham
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-08-25T08:23:46.663Z
Comments.Text: So as a workaround I've edited the crontab line to remove the ```--quiet``` command and added ```> dev/null 2>&1``` to end of the line, which as I understand dumps all output. the downside of this approach is that I won't be made aware if/when it breaks for some reason. Why is ```--quiet``` triggering an email?
Comments.UserDisplayName: Graham
Tags: <drupal><cron><drupal-9><cv>
Title: Why does Drupal 9 complain when my CiviCRM cron runs?
ThreadText: # Why does Drupal 9 complain when my CiviCRM cron runs?
  
  (Asked by: username_0 on 2023-08-20)
  
  I have a D9/Civi site and the main Civi cron is set up to run every 5 minutes using `cv` :
  
  `/usr/local/bin/cv api job.execute --user=xxx --cwd=/home/xx/sites/default/web --quiet`
  
  The cron job runs, but I get an email every time which reports:
  
  ```
  In Drupal.php line 179:
  
   \Drupal::$container is not initialized yet. \Drupal::setContainer() must be  
    called with a real container.                                               
  
  ```
  
  How can I stop this from happening? Is it do with the permissions of the selected user?
  
  **Tags:** drupal, cron, drupal-9, cv
  
  > **Comments:**
  > **username_1**: When you say "the cron job runs" are you saying that some or all of the corresponding civicrm system jobs run? If that's the case, then it's likely just one of your system jobs that is generating that message and failing.  
  > **username_1**: What happens when you run the cron job manually (as whatever user your cron is running as, without the --quiet)?  
  > **username_0**: If I run the job manually from the command line using cv and without the --quiet, I get back: ```{     "is_error": 0,     "version": 3,     "count": 1,     "values": 1 }```  
  > **username_0**: So, if I remove the ```--quiet``` parameter from the crontab I get an email with the above information. Adding it back in and I get an email with the note about $container not bneing initialized.  
  > **username_0**: So as a workaround I've edited the crontab line to remove the ```--quiet``` command and added ```> dev/null 2>&1``` to end of the line, which as I understand dumps all output. the downside of this approach is that I won't be made aware if/when it breaks for some reason. Why is ```--quiet``` triggering an email?  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2023-08-25. Score: 3
  
  I have one Drupal 9 site with this problem, and several more that don't. I don't know the root cause of the issue, but I know that adding `--level=cms-full` to the `cv` command fixes the issue.
  
  
  ---
  
  ### Answer by username_1 on 2023-08-25. Score: 2
  
  So, if your civicrm system jobs are all running, then the question is about where the extra Drupal error email is coming from (regardless of whether it gets emailed to you or just displayed on the command line when you don't use --quiet).
  
  The success of the manual run suggests one of your system jobs is generating that message but not quitting in any fatal way.
  
  I'd recommend that you look through your individual system jobs that run with each cron and run them individually via the web interface and see if they give you any clues.
  
  If that doesn't help, or if you're happy enough on the command line, you can just run them each via the command line (the civicrm system cron is just a way of selecting and running individual system jobs).
  
  I'd guess it's coming from an older extension that doesn't play well with modern Drupal, or a Drupal module that's implementing a civicrm system job.
  
  
  ---
  
  ### Answer by username_3 on 2023-08-21. Score: 1
  
  Two thoughts:
  
  * Check the version of `cv`.
  * I don't use the `cwd` option so maybe it does something different for boot ordering, and I notice `sites/default/web` is an odd path but you might just have typed that as an example. If that is the right path and it's maybe the use of `cwd`, then an alternate is change your task to be `cd /home/xx/whatever; /usr/local/bin/cv api3 ...etc...`
  
  > **Comments:**
  > **username_0**: Thanks. ```cv``` version reports as v0.3.46  
  > **username_0**: As I understand it ```cwd``` is simply used to specify the root directory (where Drupal's index.php file sits) of the site where I want the api call to be made. Maybe I should be more specific and set ```cwd``` to the path to civicrm, or cron.php?  
  
  ---
  
  