Skip to content

Airflow DAG version keeps increasing #58310

Closed

Description

@awakener1986

Apache Airflow version

Other Airflow 2/3 version (please specify below)

If "Other Airflow 2/3 version" selected, which one?

3.1.0

What happened?

We have a DAG which each time it is triggered would create 3 DAG versions. Question is why is this happening , as the impact is that the serialized_dag table is growing and would require clean up

Image

What you think should happen instead?

would like to understand how does DAG version being triggered , we would not like to have multiple versions

How to reproduce

in this example i am not sure what triggered the DAG versions being increased , but basically we are using some custom operators and looping through a list to generate python operators

Operating System

RHEL

Versions of Apache Airflow Providers

apache-airflow==3.1.0rc2
apache-airflow-core==3.1.0rc2
apache-airflow-providers-amazon==9.14.0
apache-airflow-providers-celery==3.12.3
apache-airflow-providers-cncf-kubernetes==10.5.0
apache-airflow-providers-common-compat==1.7.4
apache-airflow-providers-common-io==1.6.3
apache-airflow-providers-common-messaging==2.0.0
apache-airflow-providers-common-sql==1.28.1
apache-airflow-providers-docker==4.4.3
apache-airflow-providers-elasticsearch==6.3.3
apache-airflow-providers-fab==2.4.3
apache-airflow-providers-ftp==3.13.2
apache-airflow-providers-git==0.0.8
apache-airflow-providers-google==18.0.0
apache-airflow-providers-grpc==3.8.2
apache-airflow-providers-hashicorp==4.3.2
apache-airflow-providers-http==5.3.4
apache-airflow-providers-microsoft-azure==12.7.1
apache-airflow-providers-microsoft-mssql==4.3.2
apache-airflow-providers-mysql==6.3.4
apache-airflow-providers-odbc==4.10.2
apache-airflow-providers-openlineage==2.7.1
apache-airflow-providers-postgres==6.3.0
apache-airflow-providers-redis==4.3.1
apache-airflow-providers-sendgrid==4.1.3
apache-airflow-providers-sftp==5.4.0
apache-airflow-providers-slack==9.3.0
apache-airflow-providers-smtp==2.2.1
apache-airflow-providers-snowflake==6.5.4
apache-airflow-providers-ssh==4.1.4
apache-airflow-providers-standard==1.8.0
apache-airflow-task-sdk==1.1.0rc2

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else?

this issue occurs everytime DAG is triggered ( scheduled daily at midnight ) and will generate 3 versions

Image Image

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Nov 14, 2025
  2. boring-cyborg commented on Nov 14, 2025

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. hwang-cadent commented on Nov 14, 2025

    @hwang-cadent
    Contributor

    The list order may change between dag parses. When tasks are created in a loop, if the order or structure changes between parses, the DAG hash changes, creating new versions.

  4. gvergnolle commented on Nov 14, 2025

    @gvergnolle

    Hey @awakener1986, we started a conversation about this in Airflow's Slack. Are you part of it? Here is the link to the thread, anyone is welcome to join: https://apache-airflow.slack.com/archives/CCQ7EGB1P/p1763078254725439

    TLDR: It would be worth investigating if something changes in your dag files everytime they are parsed, this could create new versions everytime they are parsed

  5. Magellol commented on Dec 2, 2025

    @Magellol

    We've noticed on our end than doing something like this causes the DAG version to increment after a run has been triggered (when the dag processor runs again), but not if we keep forcing to parse the DAG multiple times in a row. Unclear why the difference.

    So essentially doing "parse, parse, parse" doesn't increment but "trigger run, parse, trigger run, parse" does.

    + import uuid
    
    take_snapshot = RdsCreateDbSnapshotOperator(
      task_id="take_rds_snapshot",
      db_type="instance",
      db_identifier="xxxx",
    -  db_snapshot_identifier=f"test",
    +  db_snapshot_identifier=f"test{uuid.uuid4()}",
    )

    Removing the uuid effectively prevent this increment from happening. Is there another way to create random strings which don't increment the DAG version when it runs?

  6. gvergnolle commented on Dec 2, 2025

    @gvergnolle

    You can probably use template variables, I can see there's one for uuids. I think it would be fine since they're only populated at execution, not parsing. To be tested though, this is just an intuition

  7. dabla commented on May 12, 2026

    @dabla
    Contributor

    We've noticed on our end than doing something like this causes the DAG version to increment after a run has been triggered (when the dag processor runs again), but not if we keep forcing to parse the DAG multiple times in a row. Unclear why the difference.

    So essentially doing "parse, parse, parse" doesn't increment but "trigger run, parse, trigger run, parse" does.

    • import uuid

    take_snapshot = RdsCreateDbSnapshotOperator(
    task_id="take_rds_snapshot",
    db_type="instance",
    db_identifier="xxxx",

    • db_snapshot_identifier=f"test",
    • db_snapshot_identifier=f"test{uuid.uuid4()}",
      )
      Removing the uuid effectively prevent this increment from happening. Is there another way to create random strings which don't increment the DAG version when it runs?

    This example can indeed trigger a new Dag version, it's usually a bad idea to defined dynamic stuff in operators as those may indeed influence the dag parsing which can lead to new dag version on each parse.

  8. sbrinkhorst commented on Aug 5, 2026

    @sbrinkhorst

    We recently migrated to Airflow 3.2 (from an Airflow 2 version) and I was surprised by the high version number of some DAGs but didn't pay much attention to it. After migrating to 3.3 we found out that it is actually a problem: if you go back to older DagRuns it crashes our API pods because it goes out of memory. We think this because Airflow 3.3 fixes the issue of not correctly seeing the run in the grid view for older DAGs. We parameterize our DAGs heavily and run a lot, so going back to an older run of a DAG that has 74k runs and 54k versions killed the pods. And lo and behold, it is indeed only for DAGs that have some random element in it.

    Did you do something to clean up the table, or should it be enough that we have database cleanup configured?

  9. LeonardoSanBenitez commented on Aug 6, 2026

    @LeonardoSanBenitez

    Airflow already has a check for this and it has been on by default since 3.2, which I think is the fastest way for anyone here to find out which DAG is doing it. [dag_processor] dag_version_inflation_check_level defaults to warning, and the DAG processor runs a static check on every parse (dag_version_inflation_checker.py, called from processor.py). When it fires you get a DAG warning in the UI naming the line:

    This Dag uses runtime-variable values in Dag construction.
    It causes the Dag version to increase as values change on every Dag parse.
    
    Line 7, Col 4
    Code: BashOperator(task_id='t', bash_command=f'echo test{uuid.uuid4()}')
    Issue: Don't use runtime-varying values as arguments of task within with Dag block
    

    That is the uuid4() example from earlier in this thread, run through 3.3.0. It also catches datetime.now() in the DAG constructor or inside default_args, the from uuid import uuid4 form, tasks built in a loop, and a value passed through an intermediate variable (it prints Line 6: 'run_marker' related 'uuid.uuid4()'). Setting the level to error turns it into a DAG import error instead of a warning.

    One caveat, since silence from it is not proof: it follows m = uuid.uuid4() but not m = uuid.uuid4().hex — wrapping the runtime call in an attribute access loses the trace. So it rules out the obvious patterns, not every one.

    If the check is quiet and versions still climb, the cause is probably not in the DAG file at all, and #66103 is worth reading. There the reporter compared dag_code.source_code_hash between consecutive versions, found it identical while serialized_dag.data differed, and traced it to two DAG processors disagreeing — one was running an older build of an in-house provider, so template_fields differed by one entry. Another report in that thread sees 20-70 new versions from a single rolling redeploy, which fits the same shape. Code hash unchanged plus serialized data changed means the parsing environment is varying rather than your DAG.

    On the question further up about "parse, parse, parse" not bumping the version while "trigger a run, parse" does: that is SerializedDagModel.write_dag. When the serialization changes, a new DagVersion is only created if the current version already has task instances attached; otherwise the existing row is overwritten in place, because rewriting a version that a run has already executed against would rewrite history. On 3.3.0, five consecutive parses of a DAG with a uuid4() in it left version_number at 1 while the stored hash changed every time; after attaching a task instance, each further parse added exactly one version. So the counter tracks how often the DAG changed while the previous version was already in use, which is why a high run rate turns a small non-determinism into tens of thousands of rows.

    On cleanup: dag_version is covered by airflow db clean, and on 3.3 it does drain. Six versions each pinned by an aged run went to a single row in one pass, keeping the newest version per DAG (db_cleanup.py). The constraint worth knowing is that a version still referenced by a task instance is skipped, since task_instance.dag_version_id is ON DELETE RESTRICT — so what actually governs how fast the table drains is your task_instance retention window, not anything about versions.

    If the table grew while cleanup was already configured, it is worth checking the old logs before assuming the retention window was the whole story. On 3.2.2 the same case does this:

    Checking table dag_version
    Found 5 rows meeting deletion criteria.
    [warning ] Encountered error when attempting to clean table 'dag_version'.
    [warning ] The following tables were not cleaned due to errors: ['dag_version'].
    exit code: 0
    

    Exit code 0, so a nightly job would have looked green while nothing was cleaned. On 3.3.0 the same case prints Found 0 rows meeting deletion criteria and exits cleanly. I did not reproduce the MySQL variant, where that delete is reported to hang on metadata locks (#66177).

    On the api-server running out of memory: I have not looked into that properly and cannot say it has the same root cause. The grid structure endpoint on 3.3 already limits historical versions to the runs on the current page and streams them, so it is not loading all 54k versions. Two open threads look adjacent: #69832 is a PR against that same endpoint, about it holding a database connection across deserialization for DAGs with many versions, and #64877 is the api-server hanging when you open a task that no longer exists in the latest DAG code — which is close to what going back to an older run of a heavily versioned DAG would do. If neither matches, it is probably worth its own issue with the version counts and pod memory limits in it.


    Drafted-by: Claude Code (Opus 5); reviewed by @LeonardoSanBenitez before posting.
    If you believe this contribution was not useful to the airflow community, please let me know and I will stop posting

  10. sbrinkhorst commented on Aug 7, 2026

    @sbrinkhorst

    Thank you for your elaborate answer.

    That check sounds useful, but only seems to work if people use specific methods directly in your code. In our case it is a custom helper method. I still expect that this is the cause of our trouble, because only DAGs that use the two helper methods we have identified have these inflated versions.

    Good to hear that the versions should be removed from the db with the cleanup. Once that is done I think I will set up some external monitoring on the db. It is pretty easy to query if there are a lot of versions with identical source code hashes, so I will get an alarm if someone manages to slip some randomness past the review process.

  11. LeonardoSanBenitez commented on Aug 8, 2026

    @LeonardoSanBenitez

    On the api-server memory, there is a FAQ entry for that exact symptom that I should have pointed at the first time rather than guessing: https://airflow.apache.org/docs/apache-airflow/stable/faq.html#how-to-prevent-api-server-memory-growth. The api-server holds deserialized Dag objects in memory keyed by Dag version id, and the entry ties the growth directly to version inflation. The two levers are in different states by default on 3.3, which is worth checking before anything else: [api] dag_cache_size is new in 3.3.0 and already bounded at 64 (dag_cache_ttl 3600), so unless your deployment sets it to 0 the cache is not holding 54k versions — but rolling worker recycling is off, since [api] server_type defaults to uvicorn and worker_refresh_interval to 0, and the recycling only takes effect under gunicorn. The docs note that worker recycling releases memory from any source, not only that cache. I have not measured either against a Dag your size, so that is the documented lever rather than a diagnosis of your crash.

    I also need to correct something in my earlier comment. I said that an unchanged dag_code.source_code_hash together with changed serialized data points at the parsing environment rather than at the Dag. That is wrong as a way of telling the two apart, and it matters for the monitoring you are describing. source_code_hash is a hash of the Dag file's text as read off disk (DagCode.write_code → get_code_from_file), and a file containing a random value does not change its text between parses either. On 3.3.0, five versions of a Dag with uuid.uuid4() in it share one source_code_hash and have five different dag_hash values — the same signature I attributed to #66103; as a control, editing the file between parses does give five different source_code_hash values. So that comparison separates "the file was edited" from "something else changed", and does not tell you which cause you have.

    Which makes the query you are planning a better instrument than the check for your case rather than a worse one: counting versions that share a source_code_hash looks at the result instead of the syntax, so it catches the helper-method pattern the static check misses. To go from the alarm to the cause, diffing the serialized_dag payload between two consecutive versions and seeing which field moved is the step that does separate them.

    And you are right about the check, with the limit a bit wider than "used directly": it cannot see through a function call at all, whether or not the helper lives in another file. It parses the single Dag file and only resolves a name it has itself seen assigned a recognised varying value, so run_id = uuid.uuid4() used in a task argument warns while run_id = build_run_id() does not — same file or imported, function or class method, and not even when the helper is what builds the task. Closing that would be a change to Airflow rather than something you can configure, so it is not worth waiting on; your own query is the faster route to the same alarm.


    Drafted-by: Claude Code (Opus 5); reviewed by @LeonardoSanBenitez before posting.
    If you believe this contribution was not useful to the airflow community, please let me know and I will stop posting

  12. ashb commented on Oct 13, 2026

    @ashb
    Member

    Closing this -- we can't stop the version inflation as that needs dag code to be adjusted, but it is at least visible now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:serializationkind:bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions