Copilot commented on code in PR #74093:
URL: https://github.com/apache/airflow/pull/74093#discussion_r4744245029
##########
airflow-core/src/airflow/utils/dag_version_inflation_checker.py:
##########
@@ -591,12 +593,42 @@ def check_dag_file_stability(file_path) ->
DagVersionInflationCheckResult:
if check_level == DagVersionInflationCheckLevel.off:
return DagVersionInflationCheckResult(check_level=check_level)
+ if not zipfile.is_zipfile(file_path):
+ try:
+ parsed = ast.parse(Path(file_path).read_bytes())
+ except (SyntaxError, ValueError, TypeError, FileNotFoundError):
+ return DagVersionInflationCheckResult(check_level=check_level)
+
+ checker = AirflowRuntimeVaryingValueChecker(check_level)
+ checker.visit(parsed)
+ checker.static_check_result.runtime_varying_values =
checker.varying_vars
+ return checker.static_check_result
+
+ result = DagVersionInflationCheckResult(check_level=check_level)
+
try:
- parsed = ast.parse(Path(file_path).read_bytes())
- except (SyntaxError, ValueError, TypeError, FileNotFoundError):
+ with zipfile.ZipFile(file_path) as zip_file:
+ for zip_info in zip_file.infolist():
+ if zip_info.is_dir() or not zip_info.filename.endswith(".py"):
+ continue
+
+ if not might_contain_dag(zip_info.filename, zip_file=zip_file,
conf=conf):
Review Comment:
This call always uses `might_contain_dag`'s default `safe_mode=True`, even
when `[core] dag_discovery_safe_mode=False`. The archive importer honors that
setting, so a valid member using a wrapper (for example,
`TeamDag(schedule=datetime.now())` without an `airflow` import) can be loaded
but silently bypass this stability check, including when the check level is
`error`. Pass the configured safe-mode value so checking and discovery cover
the same members.
##########
airflow-core/src/airflow/utils/sqlalchemy.py:
##########
@@ -296,6 +295,71 @@ def load_dialect_impl(self, dialect):
return super().load_dialect_impl(dialect)
+class DagRunConfJSON(TypeDecorator):
+ """Preserve finite floating-point values that use exponent notation when
stored in JSONB."""
+
+ impl = Text
+ cache_ok = True
+ should_evaluate_none = True
+
+ _FLOAT_MARKER = "__airflow_dagrun_conf_float__:"
+
+ def load_dialect_impl(self, dialect) -> TypeEngine:
+ if dialect.name == "postgresql":
+ return dialect.type_descriptor(JSONB)
+ return dialect.type_descriptor(JSON)
+
+ @classmethod
+ def _encode(cls, value):
+ if isinstance(value, float) and value == value and abs(value) !=
float("inf"):
+ encoded = json.dumps(value)
+ if "e" in encoded.lower():
+ return f"{cls._FLOAT_MARKER}{encoded}"
+ return value
+
+ if isinstance(value, str) and value.startswith(cls._FLOAT_MARKER):
+ return f"{cls._FLOAT_MARKER}{value}"
+
+ if isinstance(value, dict):
+ return {key: cls._encode(item) for key, item in value.items()}
+
+ if isinstance(value, list):
+ return [cls._encode(item) for item in value]
+
+ if isinstance(value, tuple):
+ return [cls._encode(item) for item in value]
+
+ return value
+
+ @classmethod
+ def _decode(cls, value):
+ if isinstance(value, str):
+ if value.startswith(cls._FLOAT_MARKER):
+ encoded = value[len(cls._FLOAT_MARKER) :]
+
+ if encoded.startswith(cls._FLOAT_MARKER):
+ return value[len(cls._FLOAT_MARKER) :]
Review Comment:
After upgrading, existing `DagRun.conf` strings such as
`"__airflow_dagrun_conf_float__:3.14"` are silently returned as floats, and
strings beginning with two markers lose a prefix. Bind-time escaping protects
only new writes, not existing rows. Distinguish encoded values from legacy JSON
using a versioned format with migration or separate metadata, and add a
regression test that reads a row written with the previous mapping.
##########
airflow-core/src/airflow/utils/dag_version_inflation_checker.py:
##########
@@ -591,12 +593,42 @@ def check_dag_file_stability(file_path) ->
DagVersionInflationCheckResult:
if check_level == DagVersionInflationCheckLevel.off:
return DagVersionInflationCheckResult(check_level=check_level)
+ if not zipfile.is_zipfile(file_path):
+ try:
+ parsed = ast.parse(Path(file_path).read_bytes())
+ except (SyntaxError, ValueError, TypeError, FileNotFoundError):
+ return DagVersionInflationCheckResult(check_level=check_level)
+
+ checker = AirflowRuntimeVaryingValueChecker(check_level)
+ checker.visit(parsed)
+ checker.static_check_result.runtime_varying_values =
checker.varying_vars
+ return checker.static_check_result
+
+ result = DagVersionInflationCheckResult(check_level=check_level)
+
try:
- parsed = ast.parse(Path(file_path).read_bytes())
- except (SyntaxError, ValueError, TypeError, FileNotFoundError):
+ with zipfile.ZipFile(file_path) as zip_file:
+ for zip_info in zip_file.infolist():
Review Comment:
This introduces ZIP-member Dag stability checking, which is unrelated to
preserving `DagRun.conf` numbers. It also changes operational behavior
independently: with `dag_version_inflation_check_level=error`, warnings found
by this new scan prevent the archive's Dags from loading. Please move this
change and its ZIP test into a separate PR so that the parsing-policy change
can be reviewed and validated independently of the JSONB fix.
##########
airflow-core/src/airflow/utils/dag_version_inflation_checker.py:
##########
@@ -591,12 +593,42 @@ def check_dag_file_stability(file_path) ->
DagVersionInflationCheckResult:
if check_level == DagVersionInflationCheckLevel.off:
return DagVersionInflationCheckResult(check_level=check_level)
+ if not zipfile.is_zipfile(file_path):
+ try:
+ parsed = ast.parse(Path(file_path).read_bytes())
+ except (SyntaxError, ValueError, TypeError, FileNotFoundError):
+ return DagVersionInflationCheckResult(check_level=check_level)
+
+ checker = AirflowRuntimeVaryingValueChecker(check_level)
+ checker.visit(parsed)
+ checker.static_check_result.runtime_varying_values =
checker.varying_vars
+ return checker.static_check_result
+
+ result = DagVersionInflationCheckResult(check_level=check_level)
+
try:
- parsed = ast.parse(Path(file_path).read_bytes())
- except (SyntaxError, ValueError, TypeError, FileNotFoundError):
+ with zipfile.ZipFile(file_path) as zip_file:
+ for zip_info in zip_file.infolist():
+ if zip_info.is_dir() or not zip_info.filename.endswith(".py"):
Review Comment:
This scan includes Python members that `ZipImporter._iter_supported_members`
excludes, such as `__MACOSX/old_dag.py`. If an ignored member contains a
runtime-varying Dag constructor and the check level is `error`, its warning
causes `_parse_file` to reject the archive's valid Dags too. Use the importer's
eligible definitions for stability checks rather than independently accepting
every `.py` member.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]