Skip to content

Fix: Handle MySQL emoji encoding error (1366) in DAG code insertion#62693

Open
MonsterChenzhuo wants to merge 1 commit intoapache:mainfrom
MonsterChenzhuo:pr11
Open

Fix: Handle MySQL emoji encoding error (1366) in DAG code insertion#62693
MonsterChenzhuo wants to merge 1 commit intoapache:mainfrom
MonsterChenzhuo:pr11

Conversation

@MonsterChenzhuo
Copy link
Contributor

@MonsterChenzhuo MonsterChenzhuo commented Mar 2, 2026

img_v3_02vd_4b82ab7c-54d3-4e5a-98af-2bf50163d02g

This PR improves the handling of database errors when persisting DAG source code, specifically addressing the issue where emoji or other unsupported characters in DAG files cause MySQLdb.OperationalError (1366) on databases with utf8 charset.

Previously, the INSERT INTO dag_code operation was deferred and triggered during the subsequent FAB permission sync ( session.commit() ). This caused the error to be caught by FAB's internal error handler (logged as "Creation of Permission View Error") instead of being handled as a DAG serialization error. As a result, the parsing loop would fail without reporting a visible ImportError to the user.

Changes:

  • Added explicit session.flush() in _serialize_dag_capturing_errors to force DB writes before entering permission sync.
  • This ensures that OperationalError is raised within the scope of our try-except block, allowing us to catch the 1366 error and record it as a proper ImportError .
  • Fixed a missing session argument in DagCode.update_source_code call.
  • Updated tests to verify that errors raised during flush are correctly captured.

Effect display
image


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant