john-bodley commented on code in PR #24467:
URL: https://github.com/apache/superset/pull/24467#discussion_r1238067784


##########
superset/daos/base.py:
##########
@@ -127,57 +128,72 @@ def find_one_or_none(cls, **filter_by: Any) -> 
Optional[T]:
         return query.filter_by(**filter_by).one_or_none()
 
     @classmethod
-    def create(cls, properties: dict[str, Any], commit: bool = True) -> T:
-        """
-        Generic for creating models
-        :raises: DAOCreateFailedError
+    def create(
+        cls,
+        item: T | None = None,
+        attributes: dict[str, Any] | None = None,
+        commit: bool = True,
+    ) -> T:
         """
-        if cls.model_cls is None:
-            raise DAOConfigError()
-        model = cls.model_cls()  # pylint: disable=not-callable
-        for key, value in properties.items():
-            setattr(model, key, value)
-        try:
-            db.session.add(model)
-            if commit:
-                db.session.commit()
-        except SQLAlchemyError as ex:  # pragma: no cover
-            db.session.rollback()
-            raise DAOCreateFailedError(exception=ex) from ex
-        return model
+        Create an object from the specified item and/or attributes.
 
-    @classmethod
-    def save(cls, instance_model: T, commit: bool = True) -> None:
-        """
-        Generic for saving models
-        :raises: DAOCreateFailedError
+        :param item: The object to create
+        :param attributes: The attributes associated with the object to create
+        :param commit: Whether to commit the transaction
+        :raises: DAOCreateFailedError: If the creation failed
         """
-        if cls.model_cls is None:
-            raise DAOConfigError()
+
+        if not item:
+            item = cls.model_cls()  # type: ignore  # pylint: 
disable=not-callable
+
+        if attributes:
+            for key, value in attributes.items():
+                setattr(item, key, value)
+
         try:
-            db.session.add(instance_model)
+            db.session.add(item)
+
             if commit:
                 db.session.commit()
         except SQLAlchemyError as ex:  # pragma: no cover
             db.session.rollback()
             raise DAOCreateFailedError(exception=ex) from ex
 
+        return item  # type: ignore
+
     @classmethod
-    def update(cls, model: T, properties: dict[str, Any], commit: bool = True) 
-> T:
+    def update(
+        cls,
+        item: T | None = None,

Review Comment:
   The item and/or attributes are now optional which provides more flexibility.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to