vincbeck commented on code in PR #42343:
URL: https://github.com/apache/airflow/pull/42343#discussion_r1772032501


##########
airflow/datasets/manager.py:
##########
@@ -58,12 +58,55 @@ class DatasetManager(LoggingMixin):
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
 
-    def create_datasets(self, dataset_models: list[DatasetModel], session: 
Session) -> None:
+    def create_datasets(self, datasets: list[Dataset], *, session: Session) -> 
list[DatasetModel]:
         """Create new datasets."""
-        for dataset_model in dataset_models:
-            session.add(dataset_model)
-        for dataset_model in dataset_models:
-            self.notify_dataset_created(dataset=Dataset(uri=dataset_model.uri, 
extra=dataset_model.extra))
+
+        def _add_one(dataset: Dataset) -> DatasetModel:
+            model = DatasetModel.from_public(dataset)
+            session.add(model)
+            return model
+
+        models = [_add_one(d) for d in datasets]
+        for dataset in datasets:
+            self.notify_dataset_created(dataset=dataset)
+        return models
+
+    def create_dataset_aliases(
+        self,
+        dataset_aliases: list[DatasetAlias],
+        *,
+        session: Session,
+    ) -> list[DatasetAliasModel]:
+        """Create new dataset aliases."""
+
+        def _add_one(dataset_alias: DatasetAlias) -> DatasetAliasModel:
+            model = DatasetAliasModel.from_public(dataset_alias)
+            session.add(model)
+            return model
+
+        models = [_add_one(a) for a in dataset_aliases]
+        for dataset_alias in dataset_aliases:
+            self.notify_dataset_alias_created(dataset_alias=dataset_alias)

Review Comment:
   Same



##########
newsfragments/42343.feature.rst:
##########
@@ -0,0 +1 @@
+New function ``create_dataset_aliases`` added to DatasetManager for 
DatasetAlias creation.

Review Comment:
   `DatasetManager` is not part of the public interface right? Do we need to 
call out new methods in a newsfragment? 



##########
airflow/datasets/manager.py:
##########
@@ -58,12 +58,55 @@ class DatasetManager(LoggingMixin):
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
 
-    def create_datasets(self, dataset_models: list[DatasetModel], session: 
Session) -> None:
+    def create_datasets(self, datasets: list[Dataset], *, session: Session) -> 
list[DatasetModel]:
         """Create new datasets."""
-        for dataset_model in dataset_models:
-            session.add(dataset_model)
-        for dataset_model in dataset_models:
-            self.notify_dataset_created(dataset=Dataset(uri=dataset_model.uri, 
extra=dataset_model.extra))
+
+        def _add_one(dataset: Dataset) -> DatasetModel:
+            model = DatasetModel.from_public(dataset)
+            session.add(model)
+            return model
+
+        models = [_add_one(d) for d in datasets]
+        for dataset in datasets:
+            self.notify_dataset_created(dataset=dataset)

Review Comment:
   Why not doing both operations in one for loop? We loop through the datasets 
twice in a row



##########
newsfragments/42343.significant.rst:
##########
@@ -0,0 +1,7 @@
+``DatasetManager.create_datasets`` now takes ``Dataset`` objects

Review Comment:
   Same here, my understanding is `DatasetManager` is not part of the public 
interface, therefore, it is not needed to callout breaking changes?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to