Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log action get the correct request body #45546

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

luoyuliuyin
Copy link
Contributor

Apache Airflow version

main (development)

How to reproduce

POST request with content-type as application/json; charset=utf-8

curl -X 'PATCH' \
  'https://you_host_com/api/v1/dags/dag_id/dagRuns/run_id' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json; charset=utf-8' \
  -d '{
  "state": "success"
}'

Problem Description

When an API call is made, if the API has the @action_logging annotation, the event will be recorded in the db log table as follows
image

Related Code

Currently, whether the current request contains json_body is determined by judging whether request.headers.get("content-type") is equal to application/json. The relevant code is as follows
image

But in many cases, the content-type contains other information besides application/json, such as application/json; charset=utf-8. In this case, the database will not record valid information.
image

Solution

So the judgment condition should be changed to include

pierrejeambrun
pierrejeambrun previously approved these changes Jan 10, 2025
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

Nice catch

@pierrejeambrun pierrejeambrun added the backport-to-v2-10-test Mark PR with this label to backport to v2-10-test branch label Jan 10, 2025
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

NIce.

Small nits before merging, but looking good.

tests/api_connexion/endpoints/test_dag_run_endpoint.py Outdated Show resolved Hide resolved
tests/api_connexion/endpoints/test_dag_run_endpoint.py Outdated Show resolved Hide resolved
@pierrejeambrun pierrejeambrun added the type:bug-fix Changelog: Bug Fixes label Jan 10, 2025
@luoyuliuyin
Copy link
Contributor Author

NIce.

Small nits before merging, but looking good.

Thank you for the suggestion. Please check the latest commit.

@pierrejeambrun pierrejeambrun merged commit bae4bb1 into apache:main Jan 10, 2025
7 checks passed
Copy link

Backport failed to create: v2-10-test. View the failure log Run details

Status Branch Result
v2-10-test Commit Link

You can attempt to backport this manually by running:

cherry_picker bae4bb1 v2-10-test

This should apply the commit to the v2-10-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

pierrejeambrun pushed a commit to astronomer/airflow that referenced this pull request Jan 10, 2025
@pierrejeambrun
Copy link
Member

cherry pick PR here:
#45560

ashb added a commit that referenced this pull request Jan 10, 2025
This was merged without letting tests pass somehow. We have removed the
`root_dag` argument in Airflow 3.
potiuk pushed a commit that referenced this pull request Jan 10, 2025
This was merged without letting tests pass somehow. We have removed the
`root_dag` argument in Airflow 3.
potiuk pushed a commit that referenced this pull request Jan 13, 2025
* fix: log action get the correct request body (#45546)

(cherry picked from commit bae4bb1)

* Fix log_action decorator when content type is None (#45567)

(cherry picked from commit 46304d8)

---------

Co-authored-by: luoyuliuyin <[email protected]>
Co-authored-by: Daniel Standish <[email protected]>
agupta01 pushed a commit to agupta01/airflow that referenced this pull request Jan 13, 2025
agupta01 pushed a commit to agupta01/airflow that referenced this pull request Jan 13, 2025
This was merged without letting tests pass somehow. We have removed the
`root_dag` argument in Airflow 3.
karenbraganz pushed a commit to karenbraganz/airflow that referenced this pull request Jan 13, 2025
karenbraganz pushed a commit to karenbraganz/airflow that referenced this pull request Jan 13, 2025
This was merged without letting tests pass somehow. We have removed the
`root_dag` argument in Airflow 3.
HariGS-DB pushed a commit to HariGS-DB/airflow that referenced this pull request Jan 16, 2025
HariGS-DB pushed a commit to HariGS-DB/airflow that referenced this pull request Jan 16, 2025
This was merged without letting tests pass somehow. We have removed the
`root_dag` argument in Airflow 3.
dauinh pushed a commit to dauinh/airflow that referenced this pull request Jan 24, 2025
dauinh pushed a commit to dauinh/airflow that referenced this pull request Jan 24, 2025
This was merged without letting tests pass somehow. We have removed the
`root_dag` argument in Airflow 3.
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 area:webserver Webserver related Issues backport-to-v2-10-test Mark PR with this label to backport to v2-10-test branch type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants