<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.2.1 (latest released)</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">debian</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto">apache-airflow==2.2.1<br>
apache-airflow-providers-amazon==2.3.0<br>
apache-airflow-providers-ftp==2.0.1<br>
apache-airflow-providers-google==6.0.0<br>
apache-airflow-providers-http==2.0.1<br>
apache-airflow-providers-imap==2.0.1<br>
apache-airflow-providers-jira==2.0.1<br>
apache-airflow-providers-mysql==2.1.1<br>
apache-airflow-providers-postgres==2.3.0<br>
apache-airflow-providers-redis==2.0.1<br>
apache-airflow-providers-sqlite==2.0.1<br>
apache-airflow-providers-ssh==2.2.0</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Other Docker-based deployment</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto">Dask executor, custom-built Docker images, postgres 12.7 backend</p>
<h3 dir="auto">What happened</h3>
<ol dir="auto">
<li>Shut off Airflow cluster</li>
<li>Upgraded database from 2.0.2 to 2.2.1</li>
<li>Restarted Airflow cluster</li>
<li>The scheduler failed to start</li>
<li>I checked the logs, and found this:</li>
</ol>
<details>
<pre class="notranslate">2021-11-04 21:15:35,566 ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/jobs/scheduler_job.py", line 628, in _execute
    self._run_scheduler_loop()
  File "/usr/local/lib/python3.9/site-packages/airflow/jobs/scheduler_job.py", line 709, in _run_scheduler_loop
    num_queued_tis = self._do_scheduling(session)
  File "/usr/local/lib/python3.9/site-packages/airflow/jobs/scheduler_job.py", line 782, in _do_scheduling
    self._create_dagruns_for_dags(guard, session)
  File "/usr/local/lib/python3.9/site-packages/airflow/utils/retries.py", line 76, in wrapped_function
    for attempt in run_with_db_retries(max_retries=retries, logger=logger, **retry_kwargs):
  File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 382, in __iter__
    do = self.iter(retry_state=retry_state)
  File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 349, in iter
    return fut.result()
  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 438, in result
    return self.__get_result()
  File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.9/site-packages/airflow/utils/retries.py", line 85, in wrapped_function
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/airflow/jobs/scheduler_job.py", line 847, in _create_dagruns_for_dags
    self._create_dag_runs(query.all(), session)
  File "/usr/local/lib/python3.9/site-packages/airflow/jobs/scheduler_job.py", line 917, in _create_dag_runs
    self._update_dag_next_dagruns(dag, dag_model, active_runs_of_dags[dag.dag_id])
  File "/usr/local/lib/python3.9/site-packages/airflow/jobs/scheduler_job.py", line 926, in _update_dag_next_dagruns
    if total_active_runs &gt;= dag_model.max_active_runs:
TypeError: '&gt;=' not supported between instances of 'int' and 'NoneType'
</pre>
</details>
<ol start="6" dir="auto">
<li>I checked the code and saw that dag_model.max_active_runs comes directly from the database and is nullable</li>
<li>I updated all values for dag.max_active_runs to be non-null</li>
<li>Restarted the scheduler</li>
<li>Everything ran fine</li>
</ol>
<h3 dir="auto">What you expected to happen</h3>
<p dir="auto">In this case, I would expect the code to properly handle nullable columns, probably by using the default value provided in the configs.</p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">This is easily reproducible. Start a fresh instance of Airflow with a database at version 2.2.1 and follow these steps:</p>
<ol dir="auto">
<li>Add a DAG to the instance</li>
<li>Manually set dag.max_active_runs to null in the database</li>
<li>Enable the DAG to cause the scheduler to attempt to parse/schedule it</li>
<li>BOOM! The scheduler will crash</li>
</ol>
<h3 dir="auto">Anything else</h3>
<p dir="auto">Newly registered DAGs have this value populated in the database with the default value, so this issue will likely only occur on a database upgrade.</p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.2.1 (latest released)</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Linux (ubuntu 20.04)</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apache-airflow-providers-ftp==2.0.1
apache-airflow-providers-http==2.0.1
apache-airflow-providers-imap==2.0.1
apache-airflow-providers-microsoft-azure==3.1.0
apache-airflow-providers-microsoft-mssql==2.0.0
apache-airflow-providers-postgres==2.0.0
apache-airflow-providers-salesforce==3.1.0
apache-airflow-providers-sqlite==2.0.1
apache-airflow-providers-ssh==2.1.0"><pre class="notranslate"><code class="notranslate">apache-airflow-providers-ftp==2.0.1
apache-airflow-providers-http==2.0.1
apache-airflow-providers-imap==2.0.1
apache-airflow-providers-microsoft-azure==3.1.0
apache-airflow-providers-microsoft-mssql==2.0.0
apache-airflow-providers-postgres==2.0.0
apache-airflow-providers-salesforce==3.1.0
apache-airflow-providers-sqlite==2.0.1
apache-airflow-providers-ssh==2.1.0
</code></pre></div>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Other</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto">Airflow installed on Azure virtual machine (Standard D8s v3 (8 vcpus, 32 GiB memory)), the VM is dedicated for Airflow only</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">After I updated Airflow from 2.1.3 to 2.2.1 and run db update, I run <code class="notranslate">airflow scheduler</code> and got an error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2021-11-02 11:43:20,846] {scheduler_job.py:644} ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py&quot;, line 628, in _execute
    self._run_scheduler_loop()
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py&quot;, line 709, in _run_scheduler_loop
    num_queued_tis = self._do_scheduling(session)
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py&quot;, line 782, in _do_scheduling
    self._create_dagruns_for_dags(guard, session)
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/utils/retries.py&quot;, line 76, in wrapped_function
    for attempt in run_with_db_retries(max_retries=retries, logger=logger, **retry_kwargs):
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/tenacity/__init__.py&quot;, line 382, in __iter__
    do = self.iter(retry_state=retry_state)
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/tenacity/__init__.py&quot;, line 349, in iter
    return fut.result()
  File &quot;/usr/lib/python3.8/concurrent/futures/_base.py&quot;, line 437, in result
    return self.__get_result()
  File &quot;/usr/lib/python3.8/concurrent/futures/_base.py&quot;, line 389, in __get_result
    raise self._exception
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/utils/retries.py&quot;, line 85, in wrapped_function
    return func(*args, **kwargs)
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py&quot;, line 847, in _create_dagruns_for_dags
    self._create_dag_runs(query.all(), session)
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py&quot;, line 917, in _create_dag_runs
    self._update_dag_next_dagruns(dag, dag_model, active_runs_of_dags[dag.dag_id])
  File &quot;/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py&quot;, line 926, in _update_dag_next_dagruns
    if total_active_runs &gt;= dag_model.max_active_runs:
TypeError: '&gt;=' not supported between instances of 'int' and 'NoneType'"><pre class="notranslate"><code class="notranslate">[2021-11-02 11:43:20,846] {scheduler_job.py:644} ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 628, in _execute
    self._run_scheduler_loop()
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 709, in _run_scheduler_loop
    num_queued_tis = self._do_scheduling(session)
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 782, in _do_scheduling
    self._create_dagruns_for_dags(guard, session)
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/utils/retries.py", line 76, in wrapped_function
    for attempt in run_with_db_retries(max_retries=retries, logger=logger, **retry_kwargs):
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/tenacity/__init__.py", line 382, in __iter__
    do = self.iter(retry_state=retry_state)
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/tenacity/__init__.py", line 349, in iter
    return fut.result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/utils/retries.py", line 85, in wrapped_function
    return func(*args, **kwargs)
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 847, in _create_dagruns_for_dags
    self._create_dag_runs(query.all(), session)
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 917, in _create_dag_runs
    self._update_dag_next_dagruns(dag, dag_model, active_runs_of_dags[dag.dag_id])
  File "/home/DataPipeline/.local/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 926, in _update_dag_next_dagruns
    if total_active_runs &gt;= dag_model.max_active_runs:
TypeError: '&gt;=' not supported between instances of 'int' and 'NoneType'
</code></pre></div>
<p dir="auto">The scheduler is not able to run.</p>
<h3 dir="auto">What you expected to happen</h3>
<p dir="auto">This behaviour happens right after the update. I have another VM with Airflow (the two machines are similar, the difference in location of the VM).</p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">after the update to 2.2.1, change the config in accordance with Warnings and  run <code class="notranslate">airflow scheduler</code></p>
<h3 dir="auto">Anything else</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>