Skip to content

Conversation

@ebongzzang
Copy link

What change does this PR introduce?

  • Fixes the method airflow.sdk.definitions.asset.Asset.__hash__() in task-sdk which was attempting to hash a dictionary directly, causing a TypeError.
  • The current implementation attempts to hash a dictionary directly, which is not allowed in Python since dictionaries are mutable and unhashable. This prevents Asset objects from being used in sets or as dictionary keys, which is inconsistent with the __eq__ implementation.

Changes

  • Modified __hash__ to serialize the attrs dictionary to JSON string using json.dumps(sort_keys=True) before hashing.
    • Applied the same pattern used in the codebase for hashing dictionaries:
      • Similar to airflow/triggers/base.py:147 which uses json.dumps() to serialize kwargs before hashing.
      • Similar to airflow/providers/standard/operators/python.py:834-836 which uses json.dumps(hash_dict, sort_keys=True) to create a hashable string.
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.

Copilot AI review requested due to automatic review settings January 15, 2026 04:14
@boring-cyborg
Copy link

boring-cyborg bot commented Jan 15, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a TypeError in Asset.__hash__() that was attempting to hash a dictionary directly. The fix serializes the attrs dictionary to a JSON string using json.dumps(sort_keys=True) before hashing, following the pattern used elsewhere in the codebase.

Changes:

  • Modified Asset.__hash__() to use json.dumps() for serializing the dictionary before hashing
  • Added tests for hash equality with same and different URIs

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
task-sdk/src/airflow/sdk/definitions/asset/init.py Added json import and modified __hash__ to serialize dictionary using json.dumps(sort_keys=True)
task-sdk/tests/task_sdk/definitions/test_asset.py Added two test cases to verify hash behavior for same and different URIs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ebongzzang
Copy link
Author

Apologies - the Copilot review comment was automatically generated by my GitHub account settings when I created this PR. This was unintentional.

If this is an issue for the project, I can disable Copilot and resubmit the PR. Please let me know if you'd like me to take any action.

@ebongzzang ebongzzang force-pushed the fix/asset-hash-unhashable-dict branch from acbd703 to adda76d Compare January 15, 2026 09:08
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