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

refactor: sql lab command: separate concerns into different modules #16917

Merged
merged 18 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions superset/charts/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=arguments-renamed
Copy link
Member

@john-bodley john-bodley Oct 7, 2021

Choose a reason for hiding this comment

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

@ofekisr could we move these to the lines where the issue occurs? There was an effort in #16589 to remove top-level Pylint disable checks as it's i) unclear to the reader where these violations are occurring, and ii) potentially masks issues in future changes.

I realize that this wasn't clear and so adding it to the CONTRIBUTING.md in #17016.

Copy link
Member

@amitmiran137 amitmiran137 Oct 8, 2021

Choose a reason for hiding this comment

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

Hi @john-bodley as you notice this is the only change that was done to the file.
It was done bc all of a sudden pylint required it in the CI

The recent series of pylint rules changes that was done has awaken wiered behaviour and the CI and require us to work for the pylint instead of it working for us

linting all of sudden became a disturbance we need hop over on every PR

import logging
from typing import List, Optional, TYPE_CHECKING

Expand Down
35 changes: 35 additions & 0 deletions superset/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=isinstance-second-argument-not-valid-type
from typing import Any, Dict, List, Optional, Type

from flask_appbuilder.models.filters import BaseFilter
Expand Down Expand Up @@ -89,6 +90,19 @@ def find_all(cls) -> List[Model]:
).apply(query, None)
return query.all()

@classmethod
def find_one_or_none(cls, **filter_by: Any) -> Optional[Model]:
"""
Get the first that fit the `base_filter`
"""
query = db.session.query(cls.model_cls)
if cls.base_filter:
data_model = SQLAInterface(cls.model_cls, db.session)
query = cls.base_filter( # pylint: disable=not-callable
"id", data_model
).apply(query, None)
return query.filter_by(**filter_by).one_or_none()

@classmethod
def create(cls, properties: Dict[str, Any], commit: bool = True) -> Model:
"""
Expand All @@ -109,6 +123,27 @@ def create(cls, properties: Dict[str, Any], commit: bool = True) -> Model:
raise DAOCreateFailedError(exception=ex) from ex
return model

@classmethod
def save(cls, instance_model: Model, commit: bool = True) -> Model:
"""
Generic for saving models
:raises: DAOCreateFailedError
"""
if cls.model_cls is None:
raise DAOConfigError()
if not isinstance(instance_model, cls.model_cls):
raise DAOCreateFailedError(
"the instance model is not a type of the model class"
)
try:
db.session.add(instance_model)
if commit:
db.session.commit()
except SQLAlchemyError as ex: # pragma: no cover
db.session.rollback()
raise DAOCreateFailedError(exception=ex) from ex
return instance_model

@classmethod
def update(
cls, model: Model, properties: Dict[str, Any], commit: bool = True
Expand Down
2 changes: 1 addition & 1 deletion superset/datasets/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def validate_metrics_uniqueness(dataset_id: int, metrics_names: List[str]) -> bo
return len(dataset_query) == 0

@classmethod
def update( # pylint: disable=arguments-differ
def update(
cls, model: SqlaTable, properties: Dict[str, Any], commit: bool = True
) -> Optional[SqlaTable]:
"""
Expand Down
3 changes: 2 additions & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=line-too-long
"""A collection of ORM sqlalchemy models for Superset"""
import enum
import json
Expand Down Expand Up @@ -253,7 +254,7 @@ def parameters(self) -> Dict[str, Any]:
@property
def parameters_schema(self) -> Dict[str, Any]:
try:
parameters_schema = self.db_engine_spec.parameters_json_schema() # type: ignore # pylint: disable=line-too-long
parameters_schema = self.db_engine_spec.parameters_json_schema() # type: ignore
except Exception: # pylint: disable=broad-except
parameters_schema = {}
return parameters_schema
Expand Down
Loading