korbit-ai[bot] commented on code in PR #35259: URL: https://github.com/apache/superset/pull/35259#discussion_r2374261618
########## superset-core/src/superset_core/models/__init__.py: ########## @@ -0,0 +1,16 @@ +# 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. Review Comment: ### Empty models module missing required exports <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The __init__.py file contains only license header with no actual code, making it a non-functional module that doesn't expose any models or abstractions. ###### Why this matters This prevents the models package from being properly imported and used, breaking the intended functionality of abstracting core models and DAOs behind new superset-core public APIs as stated in the developer intent. ###### Suggested change ∙ *Feature Preview* Add the necessary imports and exports to expose the CoreModel-based Database and Dataset abstractions. For example: ```python from .core_model import CoreModel from .database import Database from .dataset import Dataset __all__ = ["CoreModel", "Database", "Dataset"] ``` ###### Provide feedback to improve future suggestions [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/3b1bc1ed-c7d1-4b9e-9675-deed1546ce90/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/3b1bc1ed-c7d1-4b9e-9675-deed1546ce90?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/3b1bc1ed-c7d1-4b9e-9675-deed1546ce90?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/3b1bc1ed-c7d1-4b9e-9675-deed1546ce90?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/3b1bc1ed-c7d1-4b9e-9675-deed1546ce90) </details> <sub> 💬 Looking for more details? Reply to this comment to chat with Korbit. </sub> <!--- korbi internal id:7bd3a5a9-4288-4ff2-880d-cca791de6afa --> [](7bd3a5a9-4288-4ff2-880d-cca791de6afa) ########## superset-core/src/superset_core/models/base.py: ########## @@ -0,0 +1,74 @@ +# 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. + +"""Core model base classes.""" + +from typing import Any + +from flask_appbuilder import Model +from sqlalchemy.orm import Mapped + + +class CoreModel(Model): + """ + Abstract base class that extends Flask-AppBuilder's Model. + + This class provides the interface contract for all Superset models. + The host package provides concrete implementations. + """ + + __abstract__ = True + + +class Database(CoreModel): + """ + Interface for Database models. + + This interface defines the contract that database models should implement, + providing consistent database connectivity and metadata operations. + """ + + __abstract__ = True + + id = Mapped[int] + verbose_name = Mapped[str] + database_name = Mapped[str | None] + + @property + def name(self) -> str: + raise NotImplementedError + + @property + def backend(self) -> str: + raise NotImplementedError + + @property + def data(self) -> dict[str, Any]: + raise NotImplementedError + + +class Dataset(CoreModel): + """ + Interface for Dataset models. + + This Interface defines the contract that dataset models should implement, + providing consistent data source operations and metadata. + + It provides the public API for Datasets implemented by the host application. + """ + + __abstract__ = True Review Comment: ### Incomplete Abstract Interface Definition <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The Dataset class is defined as an abstract interface but lacks any abstract methods or properties that implementing classes must provide. ###### Why this matters Without defined abstract methods, there's no clear contract for what functionality implementing classes must provide, which could lead to inconsistent implementations and make the codebase harder to maintain. ###### Suggested change ∙ *Feature Preview* Define the essential abstract methods/properties that all Dataset implementations must provide. For example: ```python class Dataset(CoreModel): __abstract__ = True @property @abstractmethod def name(self) -> str: """Return the dataset name.""" @property @abstractmethod def data_source(self) -> str: """Return the data source type.""" ``` ###### Provide feedback to improve future suggestions [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0c73336b-6ee7-4f42-bf70-84bf91030484/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0c73336b-6ee7-4f42-bf70-84bf91030484?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0c73336b-6ee7-4f42-bf70-84bf91030484?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0c73336b-6ee7-4f42-bf70-84bf91030484?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/0c73336b-6ee7-4f42-bf70-84bf91030484) </details> <sub> 💬 Looking for more details? Reply to this comment to chat with Korbit. </sub> <!--- korbi internal id:fab8f060-c984-435f-95a3-5a267ba32870 --> [](fab8f060-c984-435f-95a3-5a267ba32870) ########## superset-core/src/superset_core/dao/types.py: ########## @@ -0,0 +1,127 @@ +# 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. + +"""Protocol interfaces for Data Access Objects.""" + +from abc import ABC, abstractmethod +from typing import Any, Generic, Optional, TypeVar, Union + +from flask_appbuilder.models.filters import BaseFilter +from flask_sqlalchemy import BaseQuery + +from superset_core.models.base import CoreModel + +# Type variable bound to our CoreModel +T_Model = TypeVar("T_Model", bound=CoreModel) + + +class BaseDAO(Generic[T_Model], ABC): + """ + Interface for Data Access Objects. + + This interface defines the base that all DAOs should implement, + providing consistent CRUD operations across Superset and extensions. + + Extension developers should implement this protocol: + + ```python + from superset_core.dao import BaseDAO + from superset_core.models import CoreModel + + class MyDAO(BaseDAO[MyCustomModel]): + model_cls = MyCustomModel + + @classmethod + def find_by_id(cls, model_id: str | int) -> MyCustomModel | None: + # Implementation here + pass + ``` + """ + + # Class attributes that implementations should define + model_cls: Optional[type[T_Model]] + base_filter: Optional[BaseFilter] + id_column_name: str + uuid_column_name: str + + @abstractmethod + def find_by_id( + self, model_id: Union[str, int], skip_base_filter: bool = False + ) -> Optional[T_Model]: + """Find a model by ID.""" + ... + + @abstractmethod + def find_by_id_or_uuid( + self, + model_id_or_uuid: str, + skip_base_filter: bool = False, + ) -> Optional[T_Model]: + """Find a model by ID or UUID.""" + ... + + @abstractmethod + def find_by_ids( + self, + model_ids: Union[list[str], list[int]], + skip_base_filter: bool = False, + ) -> list[T_Model]: Review Comment: ### Missing batching guidance for bulk ID queries <sub></sub> <details> <summary>Tell me more</summary> ###### What is the issue? The find_by_ids method accepts a list of IDs but doesn't specify batching behavior, potentially leading to inefficient N+1 query patterns or oversized queries when implementations handle large ID lists. ###### Why this matters Without guidance on batching, implementations may either execute individual queries for each ID (N+1 problem) or attempt to query thousands of IDs at once, hitting database query size limits or causing memory issues. ###### Suggested change ∙ *Feature Preview* Add documentation or parameters to guide implementations on batching large ID lists. Consider adding a batch_size parameter with a reasonable default: ```python @abstractmethod def find_by_ids( self, model_ids: Union[list[str], list[int]], skip_base_filter: bool = False, batch_size: Optional[int] = 1000, ) -> list[T_Model]: """Find models by list of IDs. Large lists are processed in batches.""" ... ``` ###### Provide feedback to improve future suggestions [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/ff0f2164-bf5b-4f55-b39d-6a575d9892ba/upvote) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/ff0f2164-bf5b-4f55-b39d-6a575d9892ba?what_not_true=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/ff0f2164-bf5b-4f55-b39d-6a575d9892ba?what_out_of_scope=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/ff0f2164-bf5b-4f55-b39d-6a575d9892ba?what_not_in_standard=true) [](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/ff0f2164-bf5b-4f55-b39d-6a575d9892ba) </details> <sub> 💬 Looking for more details? Reply to this comment to chat with Korbit. </sub> <!--- korbi internal id:dc3f7c2f-b0f5-47df-a1a1-d7513d6150c5 --> [](dc3f7c2f-b0f5-47df-a1a1-d7513d6150c5) -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org