Repository navigation
Description
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
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
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Nov 14, 2025
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.
hwang-cadent commentedon Nov 14, 2025
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.
gvergnolle commentedon Nov 14, 2025
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
Magellol commentedon Dec 2, 2025
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.
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?
gvergnolle commentedon Dec 2, 2025
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
dabla commentedon May 12, 2026
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.
sbrinkhorst commentedon Aug 5, 2026
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?
LeonardoSanBenitez commentedon Aug 6, 2026
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_leveldefaults towarning, and the DAG processor runs a static check on every parse (dag_version_inflation_checker.py, called fromprocessor.py). When it fires you get a DAG warning in the UI naming the line:That is the
uuid4()example from earlier in this thread, run through 3.3.0. It also catchesdatetime.now()in the DAG constructor or insidedefault_args, thefrom uuid import uuid4form, tasks built in a loop, and a value passed through an intermediate variable (it printsLine 6: 'run_marker' related 'uuid.uuid4()'). Setting the level toerrorturns 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 notm = 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_hashbetween consecutive versions, found it identical whileserialized_dag.datadiffered, and traced it to two DAG processors disagreeing — one was running an older build of an in-house provider, sotemplate_fieldsdiffered 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 newDagVersionis 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 auuid4()in it leftversion_numberat 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_versionis covered byairflow 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, sincetask_instance.dag_version_idisON DELETE RESTRICT— so what actually governs how fast the table drains is yourtask_instanceretention 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:
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 criteriaand 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
sbrinkhorst commentedon Aug 7, 2026
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.
LeonardoSanBenitez commentedon Aug 8, 2026
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_sizeis new in 3.3.0 and already bounded at 64 (dag_cache_ttl3600), so unless your deployment sets it to 0 the cache is not holding 54k versions — but rolling worker recycling is off, since[api] server_typedefaults touvicornandworker_refresh_intervalto0, and the recycling only takes effect undergunicorn. 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_hashtogether 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_hashis 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 withuuid.uuid4()in it share onesource_code_hashand have five differentdag_hashvalues — the same signature I attributed to #66103; as a control, editing the file between parses does give five differentsource_code_hashvalues. 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_hashlooks 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 theserialized_dagpayload 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 whilerun_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
ashb commentedon Oct 13, 2026
Closing this -- we can't stop the version inflation as that needs dag code to be adjusted, but it is at least visible now.