You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "yermalov-here (via GitHub)" <gi...@apache.org> on 2023/09/16 14:16:27 UTC

[GitHub] [airflow] yermalov-here opened a new pull request, #34418: Add Listener hooks for Datasets

yermalov-here opened a new pull request, #34418:
URL: https://github.com/apache/airflow/pull/34418

   <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
   
      http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   This PR creates listener hooks for the following Dataset events
   * on_dataset_created
   * on_dataset_changed
   
   closes: #34327 
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   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](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on code in PR #34418:
URL: https://github.com/apache/airflow/pull/34418#discussion_r1366703285


##########
airflow/models/dag.py:
##########
@@ -3177,11 +3179,11 @@ def bulk_write_to_db(
                 stored_dataset.is_orphaned = expression.false()
                 stored_datasets[stored_dataset.uri] = stored_dataset
             else:
-                session.add(dataset)
-                stored_datasets[dataset.uri] = dataset
-
-        session.flush()  # this is required to ensure each dataset has its PK loaded

Review Comment:
   Is it possible that this flush is not only responsible for ensuring the dataset PK availability, but for something more and that results into tests flakiness?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "mobuchowski (via GitHub)" <gi...@apache.org>.
mobuchowski commented on PR #34418:
URL: https://github.com/apache/airflow/pull/34418#issuecomment-1795149986

   One question - on which Airflow component (scheduler, worker...) datasets are updated?
   
   It would be nice to add this to docstring, probably for the rest of the methods (in some separate PR). For now it's only mentioned [here](https://github.com/apache/airflow/blob/55963de61edbbaa5f54d70f94e3f4682e824743f/docs/apache-airflow-providers-openlineage/guides/structure.rst#L26).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on code in PR #34418:
URL: https://github.com/apache/airflow/pull/34418#discussion_r1366703285


##########
airflow/models/dag.py:
##########
@@ -3177,11 +3179,11 @@ def bulk_write_to_db(
                 stored_dataset.is_orphaned = expression.false()
                 stored_datasets[stored_dataset.uri] = stored_dataset
             else:
-                session.add(dataset)
-                stored_datasets[dataset.uri] = dataset
-
-        session.flush()  # this is required to ensure each dataset has its PK loaded

Review Comment:
   Is it possible that this flush is not only responsible for ensuring the dataset PK availability, but for something more and that results into tests flakiness?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on PR #34418:
URL: https://github.com/apache/airflow/pull/34418#issuecomment-1793713163

   > Some tests shoudl be marked as DB tests- see the error and link describing what needs to be done.
   
   got it. will take a look


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on PR #34418:
URL: https://github.com/apache/airflow/pull/34418#issuecomment-1798125114

   > One question - on which Airflow component (scheduler, worker...) datasets are updated?
   > 
   > It would be nice to add this to docstring, probably for the rest of the methods (in some separate PR). For now it's only mentioned [here](https://github.com/apache/airflow/blob/55963de61edbbaa5f54d70f94e3f4682e824743f/docs/apache-airflow-providers-openlineage/guides/structure.rst#L26).
   
   i can be wrong due to the lack of knowledge, but afaiu scheduler is responsible for creating new datasets and workers for updating them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on code in PR #34418:
URL: https://github.com/apache/airflow/pull/34418#discussion_r1366703285


##########
airflow/models/dag.py:
##########
@@ -3177,11 +3179,11 @@ def bulk_write_to_db(
                 stored_dataset.is_orphaned = expression.false()
                 stored_datasets[stored_dataset.uri] = stored_dataset
             else:
-                session.add(dataset)
-                stored_datasets[dataset.uri] = dataset
-
-        session.flush()  # this is required to ensure each dataset has its PK loaded

Review Comment:
   Is it possible that this flush is not only responsible for ensuring the dataset PK availability, but for something more and that results into tests flakiness?
   Currently I'm moving it together with the `session.add(dataset)` and it is only called if new datasets are created.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #34418:
URL: https://github.com/apache/airflow/pull/34418#discussion_r1360237642


##########
airflow/datasets/manager.py:
##########
@@ -44,6 +45,13 @@ class DatasetManager(LoggingMixin):
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
 
+    def create_datasets(self, dataset_models: list[DatasetModel], session: Session) -> None:
+        """Create new datasets."""
+        for dataset_model in dataset_models:
+            session.add(dataset_model)
+            self.notify_dataset_created(dataset=Dataset(uri=dataset_model.uri, extra=dataset_model.extra))
+        session.flush()  # this is required to ensure each dataset has its PK loaded

Review Comment:
   This called the hook before the database is flushed (i.e. before the rows can actually appear in the database), while the changed hook is called after flushing. I feel this should be more consistent.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on code in PR #34418:
URL: https://github.com/apache/airflow/pull/34418#discussion_r1366703285


##########
airflow/models/dag.py:
##########
@@ -3177,11 +3179,11 @@ def bulk_write_to_db(
                 stored_dataset.is_orphaned = expression.false()
                 stored_datasets[stored_dataset.uri] = stored_dataset
             else:
-                session.add(dataset)
-                stored_datasets[dataset.uri] = dataset
-
-        session.flush()  # this is required to ensure each dataset has its PK loaded

Review Comment:
   Is it possible that this flush is not only responsible for ensuring the dataset PK availability, but for something more and that results into tests flakiness?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "yermalov-here (via GitHub)" <gi...@apache.org>.
yermalov-here commented on code in PR #34418:
URL: https://github.com/apache/airflow/pull/34418#discussion_r1365271703


##########
airflow/datasets/manager.py:
##########
@@ -44,6 +45,13 @@ class DatasetManager(LoggingMixin):
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
 
+    def create_datasets(self, dataset_models: list[DatasetModel], session: Session) -> None:
+        """Create new datasets."""
+        for dataset_model in dataset_models:
+            session.add(dataset_model)
+            self.notify_dataset_created(dataset=Dataset(uri=dataset_model.uri, extra=dataset_model.extra))
+        session.flush()  # this is required to ensure each dataset has its PK loaded

Review Comment:
   Addressed in https://github.com/apache/airflow/pull/34418/commits/c471bde88ba025d098c541b35e38d880ce368776
   `on_dataset_created` hook is now called after the database is flushed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #34418:
URL: https://github.com/apache/airflow/pull/34418#issuecomment-1792801481

   Some tests shoudl be marked as DB tests- see the error and link describing what needs to be done.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Listener hooks for Datasets [airflow]

Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil merged PR #34418:
URL: https://github.com/apache/airflow/pull/34418


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org