Skip to content

Add HttpOperator JSON serialization support with tests#382

Merged
pankajastro merged 4 commits into
astronomer:mainfrom
a-chumagin:http_operator_support
Mar 29, 2025
Merged

Add HttpOperator JSON serialization support with tests#382
pankajastro merged 4 commits into
astronomer:mainfrom
a-chumagin:http_operator_support

Conversation

@a-chumagin

Copy link
Copy Markdown
Contributor

This PR resolved issue #370

Add HttpOperator JSON serialization support with tests

  • Add utility function for JSON serialization of HTTP request data
  • Add automatic Content-Type header handling for HttpOperator
  • Support both dictionary and string JSON inputs with validation
  • Add comprehensive tests for HttpOperator serialization
  • Add YAML examples for HTTP operator configuration

Additionally:

  • Fix Makefine

Tested by:

  1. Running Airflow with DagFactory
  2. Executing a DAG with HttpOperator tasks
  3. Verifying request body format with an echo-server
  4. Confirming proper Content-Type headers are set

- Add JSON serialization utility function
- Add HttpOperator Content-Type header handling
- Create dedicated test file for HTTP operators
- Add utils tests for JSON serialization
- Add YAML fixture files for testing
- Support dict and string JSON inputs with validation
- Ensure proper Content-Type headers
- Test dependencies between HTTP tasks
@a-chumagin a-chumagin requested a review from a team as a code owner March 25, 2025 10:41

@tatiana tatiana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @a-chumagin, thank you very much for implementing this.

It seems several checks in the CI are currently failing. An example of the last run:
https://github.com/astronomer/dag-factory/actions/runs/14057622752/job/39360581792?pr=382

Please, could you fix them?

The contributing guide may help:
https://astronomer.github.io/dag-factory/latest/contributing/howto/#run-integration-tests

Plase, let us know if you have any questions.

@a-chumagin

Copy link
Copy Markdown
Contributor Author

@tatiana hello!
It looks like dependences issues between airflow and http libs. I try to fix this.
Also for some reason could of failed tests locally and here are different .

@tatiana tatiana added this to the DAG Factory 0.23.0 milestone Mar 25, 2025
@codecov-commenter

codecov-commenter commented Mar 26, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.

Project coverage is 93.87%. Comparing base (d5373cd) to head (73c6409).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
dagfactory/dagbuilder.py 82.35% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #382      +/-   ##
==========================================
- Coverage   94.01%   93.87%   -0.14%     
==========================================
  Files          11       11              
  Lines         886      915      +29     
==========================================
+ Hits          833      859      +26     
- Misses         53       56       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pankajastro pankajastro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking great, thanks for implementing this!

Comment thread pyproject.toml
Comment thread tests/fixtures/dag_factory_http_operator_task.yml Outdated
Comment thread dev/dags/example_simple_http_operator_task.yml
@a-chumagin

Copy link
Copy Markdown
Contributor Author

HTTP Operator Compatibility

Airflow Version Challenges

Supporting HTTP operators across multiple Airflow versions required handling differences in operator naming and import paths:

  • Airflow 2.0 - providers-http 4.10.0: SimpleHttpOperator in airflow.providers.http.operators.http
  • Airflow providers-http >= 4.11.0: HttpOperator (renamed)

To ensure compatibility, we implemented dynamic imports:

try:
    from airflow.providers.http.operators.http import HttpOperator
    HTTP_OPERATOR_CLASS = HttpOperator
except ImportError:
    try:
        from airflow.providers.http.operators.http import SimpleHttpOperator
        HTTP_OPERATOR_CLASS = SimpleHttpOperator
    except ImportError:
        HTTP_OPERATOR_CLASS = None

Generalized Testing

To handle both SimpleHttpOperator and HttpOperator:

  1. Parametrized tests were created to work with either operator.
  2. Conditional test skipping was implemented for unsupported versions.
  3. Dynamic fixture selection was used based on the operator class:
    if HTTP_OPERATOR_PATH == "airflow.providers.http.operators.http.HttpOperator":
        fixture_path = "tests/fixtures/dag_factory_http_operator_task.yml"
    else:
        fixture_path = "tests/fixtures/dag_factory_simple_http_operator_task.yml"

Integration Test Limitations

Integration testing faced the following constraints:

  1. Complex CI setup was required to test across multiple Airflow versions.
  2. Mock servers or specialized environments were needed to verify HTTP requests.
  3. Serialization differences across versions required version-specific assertions.

Unit tests were prioritized to ensure compatibility while minimizing the need for complex integration setups.

Co-authored-by: Pankaj Singh <98807258+pankajastro@users.noreply.github.com>
Comment thread pyproject.toml Outdated
@pankajastro pankajastro merged commit b06563d into astronomer:main Mar 29, 2025
@pankajastro pankajastro mentioned this pull request Mar 29, 2025
@pankajastro pankajastro removed this from the DAG Factory 0.23.0 milestone Jul 8, 2025
pankajastro added a commit that referenced this pull request Jul 14, 2025
## [0.23.0] - 2025-07-14

### Breaking Change

- Drop Airflow 2.2 Support by @pankajastro in
[#388](#388)
- Drop Python 3.8 support by @pankajastro in
[#435](#435)
- Drop Airflow 2.3 Support by @pankajastro in
[#456](#456)

### Airflow 3 Support

- Add tools for Dag-factory Airflow3 testing by @pankajastro in
[#395](#395)
- Fix schedule args for Airflow 3 by @pankajastro in
[#413](#413)
- Fix import path for BranchPythonOperator, PythonOperator and
PythonSensor by @pankajastro in
[#414](#414)
- Add scheduling docs for Airflow 3 by @pankajastro in
[#424](#424)
- Enable Airflow 3 tests in CI by @pankajastro in
[#436](#436)
- Add env AUTO_CONVERT_TO_AF3 in Dockerfile by @pankajastro in
[#455](#455)
- Validate DAG's on Airflow 3 by @pankajastro in
[#457](#457)
- Refactor schedule to use the Python object @pankajastro in
[#458](#458)
- Fix CI and import issues for Airflow 3 compatibility @pankajastro in
[#463](#463)

### Added

- Add support for defining inlets by @IvanSviridov in
[#380](#380)
- Add HttpOperator JSON serialization support with tests by @a-chumagin
in [#382](#382)
- Add support for custom Python object by @pankajastro in
[#444](#444)
- Support env var in default by @gyli in
[#452](#452)
- Pass default arguments via dictionary in .py file by @jroachgolf84 in
[#465](#465)

### Fixed

- Remediated ``default`` behavior, added documentation by @jroachgolf84
in [#378](#378)
- Upgrade `apache-airflow-providers-cncf-kubernetes` provider by
@pankajastro in
[#407](#407)
- Include error message trace in exception by @pankajastro in
[#408](#408)

### Docs

- Remove Unreleased heading section from the CHANGELOG.md by @pankajkoti
in [#365](#365)
- Add Documentation for Conditional Dataset Scheduling with dag-factory
by @ErickSeo in
[#367](#367)
- Add copy right in docs footer by @pankajastro in
[#371](#371)
- Updating docs for callbacks by @jroachgolf84 in
[#375](#375)
- Add stable/latest version in docs by @pankajastro in
[#391](#391)
- Migrate old content to new documentation structure by @pankajastro in
[#393](#393)
- Update Airflow supported version 2.3+ in docs by @pankajastro in
[#412](#412)
- Doc: Add step to fork repo in contributing guide by @pankajastro in
[#427](#427)
- Add setting CONFIG_ROOT_DIR in the contribution doc by @gyli in
[#432](#432)
- Add DAG example showcasing runtime params usage by @pankajastro in
[#449](#449)
- Add jinja2 template example by @pankajastro in
[#450](#450)

### Others

- Add Scraf Pixels for telemetry by @pankajastro in
[#373](#373)
- feat: bumped http provider versions to 2.0+ by @a-chumagin in
[#389](#389)
- Add --verbosity debug in astro-cli cmd by @pankajastro in
[#390](#390)
- Add missing Python file for dynamic task example by @pankajastro in
[#392](#392)
- Pin apache-airflow-providers-cncf-kubernetes<10.4.2 by @pankajastro in
[#400](#400)
- Add script to check version and tag by @pankajastro in
[#395](#394)
- Assert DagRunState in integration test by @pankajastro in
[#415](#415)
- Move to uv for package management by @jlaneve in
[#419](#419)
- Install uv in CI by @jlaneve in
[#421](#421)
- Bump astral-sh/setup-uv from 5 to 6 by @dependabot in
[#423](#423)
- Add Airflow 2.11 in test matrix by @pankajastro in
[#425](#425)
- fix example_dag_factory.yml typo causing catchup: false to not be
respected by @RNHTTR in
[#431](#431)
- Remove expandvars in utils.get_python_callable by @gyli in
[#440](#440)
- Delete unused img folder by @pankajastro in
[#446](#446)
- Clean print statement by @pankajastro
[#447](#447)
- Add hatch to uv dev dependencies by @gyli in
[#453](#453)
- Add Authorize Job in CI by @pankajastro in
[#460](#460)
- Remove PyPI token for releasing packages by @tatiana in
[#461](#461)
- Change CI on trigger event to pull_request from pull_request_target by
@pankajkoti in
[#464](#464)
- Update cicd.yaml: Use pull_request for authorize as we don't have
pull_request_target event configured by @pankajkoti in
[#466](#466)
- Add environment for pypi publish job by @pankajastro in
[#478](#478)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants