Search code examples
sqlalchemyairflowflask-sqlalchemyairflow-schedulerairflow-2.x

how can I stop the [UtcDateTime cache_ok ]warn? When I run airflow dag


when I run airflow server : My version is airflow lastest(2.2).when I run the program,the dag log

"SAWarning: TypeDecorator UtcDateTime(timezone=True) will not produce a cache key because the ``cache_ok`` attribute is not set to True.  This can have significant performance implications including some performance degradations in comparison to prior SQLAlchemy versions.  Set this attribute to True if this type object's state is safe to use in a cache key, or False to disable this warning. (Background on this error at: https://sqlalche.me/e/14/cprf)
  return session.query(DagRun)"
====
the scheduler  log:
/airflow/jobs/scheduler_job.py:944 SAWarning: TypeDecorator UtcDateTime(timezone=True) will not produce a cache key because the ``cache_ok`` attribute is not set to True.
===

I had added "cache_ok = true" to airflow.cfg,or "scheduler_job.py" Class,but not slove it


Solution

  • This is due to change in SQLAlchemy 1.4 (see release notes)

    If you get this warning it means that you did not install Airflow from constraints (see docs) as in constraints for Airflow 2.2.3 it has SQLAlchemy==1.3.24

    As for future versions Airflow 2.2.4 limits the lib version to <1.4 to as you can see from this PR