Skip to content

Fix 500 error for event logs with NULL dttm - #68338

Merged
pierrejeambrun merged 4 commits into
apache:mainfrom
Vasu-Madaan:fix-event-log-null-dttm
Jun 10, 2026
Merged

pierrejeambrun merged 4 commits into
apache:mainfrom
Vasu-Madaan:fix-event-log-null-dttm

Conversation

@Vasu-Madaan

Copy link
Copy Markdown
Contributor

Summary

Log.dttm is nullable at the database level, but EventLogResponse.dttm (when in the API) is declared as a non-optional datetime. When a log row has dttm=NULL, FastAPI/Pydantic raises a validation error producing a 500 Internal Server Error instead of a sensible response.

This happens for legacy records or rows inserted directly into the database bypassing the model (which always sets dttm = timezone.utcnow() in __init__).

Why this approach

Rather than making when nullable in the API schema (a breaking contract change that would affect all API consumers expecting a non-null timestamp), we filter out null-dttm rows at the query level:

  • GET /eventLogs/{id} — returns 404 for a log whose dttm is NULL. The resource is not serveable through this API.
  • GET /eventLogs — silently excludes null-dttm rows from both the results and total_entries, keeping the response consistent and well-typed.

This is the minimal, safe fix: it stops the 500 crash without changing the API contract or requiring a schema migration.

closes: #68333


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (claude-sonnet-4-6)

Generated-by: Claude Code (claude-sonnet-4-6) following the guidelines

Logs with dttm=NULL cause a Pydantic validation error (500) because
EventLogResponse.dttm is non-optional. Filter them out at the query
level: GET /eventLogs/{id} returns 404, GET /eventLogs excludes them
from results and total_entries.

closes: apache#68333
@ashb

ashb commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

This is sort of just papering over the crack. The DB table should be changed to not allow nullable value since everything else in Airflow expects it to not be null.

But such a migration needs to be done with care, as the log table is often one of the largest and has more rows than ti, so such a migration might be horrifically slow.

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice short term workaround.

+1 for adding comments there as to why this is filtered out, and why changing the 'response' model isn't a good idea.

@pierrejeambrun
pierrejeambrun merged commit ac82cec into apache:main Jun 10, 2026
77 checks passed
@Vasu-Madaan
Vasu-Madaan deleted the fix-event-log-null-dttm branch June 10, 2026 16:16
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.0 milestone Jun 15, 2026
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit Log /eventLogs returns 500 when log.dttm is NULL

4 participants