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

Update datasets.rst issue with running example code #35035

Merged
merged 1 commit into from Oct 26, 2023

Conversation

erik-farmer
Copy link
Contributor

Fixes two small issues with running code from the dataset.rst example.

dataset_list is a list so running print(dataset, dataset_list, dataset_list[dataset]) causes a TypeError: list indices must be integers or slices, not str

Additionally the attribute name should be dag_id and not dag_run_id


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

dataset list is a list so running `print(dataset, dataset_list, dataset_list[dataset])` causes a `TypeError: list indices must be integers or slices, not str`

lastly that attribute name should be `dag_id` and not `dag_run_id`
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 18, 2023

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 Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits 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: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

print(dataset, dataset_list, dataset_list[dataset])
print(dataset_list[dataset][0].source_dag_run.dag_run_id)
print(dataset, dataset_list)
print(dataset_list[0].source_dag_run.dag_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking the signature of triggering_dataset_events in airflow/utils/context.pyi is defined with typing Mapping[str, Collection[DatasetEvent | DatasetEventPydantic]].

I assume the example is also after correction not correct, it rather needs to be (see airflow/models/dataset.py:275):

Suggested change
print(dataset_list[0].source_dag_run.dag_id)
print(dataset_list[0].source_dag_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both are correct:

Running:

        for dataset, dataset_list in triggering_dataset_events.items():
            print(dataset, dataset_list)
            print(f"{dataset_list[0].source_dag_run.dag_id=}")
            print(f"{dataset_list[0].source_dag_id=}")

results in:

[2023-10-18, 19:34:38 UTC] {logging_mixin.py:151} INFO - local://some_file.txt [DatasetEvent(id=6, dataset_id=6, extra={}, source_task_id='producer_task', source_dag_id='producer_dag', source_run_id='manual__2023-10-18T19:34:37.507108+00:00', source_map_index=-1)]
[2023-10-18, 19:34:38 UTC] {logging_mixin.py:151} INFO - dataset_list[0].source_dag_run.dag_id='producer_dag'
[2023-10-18, 19:34:38 UTC] {logging_mixin.py:151} INFO - dataset_list[0].source_dag_id='producer_dag'

(Granted my test dag is producer_dag and not load_snowflake_data from the demo.

I'm open to either but I like showing source_dag_run because it can also hint at getting items like. source_dag_run.data_interval_start which could be useful for the consumer dag

Copy link
Contributor

Choose a reason for hiding this comment

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

Aaah, yes, you are right. I over-looked /home/jscheffl/Workspace/airflow/airflow/models/dataset.py:304 where the relation is modelled. Danger-zone is that from typing it can be also class of type DatasetEventPydantic if airflow switches to use internal API and this does not carry the relation parameter. Internal API is coming, adding a bit of more API complexity here for the future benefit of multi tenancy.

Copy link
Member

@hussein-awala hussein-awala left a comment

Choose a reason for hiding this comment

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

Looks good!

@pankajastro pankajastro merged commit 8e26894 into apache:main Oct 26, 2023
44 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 26, 2023

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@ephraimbuddy ephraimbuddy added the type:doc-only Changelog: Doc Only label Oct 27, 2023
@ephraimbuddy ephraimbuddy added this to the Airflow 2.7.3 milestone Oct 27, 2023
ephraimbuddy pushed a commit that referenced this pull request Oct 29, 2023
dataset list is a list so running `print(dataset, dataset_list, dataset_list[dataset])` causes a `TypeError: list indices must be integers or slices, not str`

lastly that attribute name should be `dag_id` and not `dag_run_id`

(cherry picked from commit 8e26894)
ephraimbuddy pushed a commit that referenced this pull request Oct 30, 2023
dataset list is a list so running `print(dataset, dataset_list, dataset_list[dataset])` causes a `TypeError: list indices must be integers or slices, not str`

lastly that attribute name should be `dag_id` and not `dag_run_id`

(cherry picked from commit 8e26894)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants