You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "hughhhh (via GitHub)" <gi...@apache.org> on 2023/04/06 15:29:59 UTC

[GitHub] [superset] hughhhh opened a new pull request, #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

hughhhh opened a new pull request, #23614:
URL: https://github.com/apache/superset/pull/23614

   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   Currently experiencing errors in production where charts/slices are being saved with datasource_type = "query". Currently charts can only be powered by SqlaTable models.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] john-bodley commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1160146589


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   You'll also have to update the `params` which has `datasource` field defined as `<datasource_id>_<datasource_type>`.



##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,60 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)

Review Comment:
   This is unused.



##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   @hughhhh we're seeing a defined `slices.datasource_name` column when `slices.datasource_type = 'query'` however it doesn't seem to be a dataset in the `tables` table—which would indicate that your migration would likely break said slices when you make the switch from `query` to `table`. BTW where is this query stored?



##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,60 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))

Review Comment:
   This is unused.



-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] hughhhh commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "hughhhh (via GitHub)" <gi...@apache.org>.
hughhhh commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1165671066


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   so the idea here was to try and see if some of them will work if we change the type, since we can't just delete these charts. We are assuming these charts are failing already and hoping this might help fix it, but no guarantee. Also now with the constraint we should see error when the user/api tries to write slice.datasource_type = query



-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] hughhhh commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "hughhhh (via GitHub)" <gi...@apache.org>.
hughhhh commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1160275651


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   this is the stack trace we are encountering in production:
   ```
   return [
     File "/usr/local/lib/python3.8/site-packages/marshmallow/schema.py", line 515, in <listcomp>
       self._serialize(d, many=False)
     File "/usr/local/lib/python3.8/site-packages/marshmallow/schema.py", line 520, in _serialize
       value = field_obj.serialize(attr_name, obj, accessor=self.get_attribute)
     File "/usr/local/lib/python3.8/site-packages/marshmallow/fields.py", line 338, in serialize
       return self._serialize(value, attr, obj, **kwargs)
     File "/usr/local/lib/python3.8/site-packages/marshmallow/fields.py", line 1922, in _serialize
       return self._call_or_raise(self.serialize_func, obj, attr)
     File "/usr/local/lib/python3.8/site-packages/marshmallow/fields.py", line 1936, in _call_or_raise
       return func(value)
     File "/usr/local/lib/python3.8/site-packages/superset/models/slice.py", line 167, in datasource_url
       return datasource.explore_url if datasource else None
   AttributeError: 'Query' object has no attribute 'explore_url'
   ```



-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] john-bodley commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1162165263


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   @hughhhh per your response,
   
   > So those slices are most likely broken, because charts/slices don't know who to execute grabbing data when the datasource_type is Query
   
   I guess the question/concern is simply changing the `datasource_type` to `table` doesn't really mitigate the problematic charts as the `datasource_id` is then likely incorrect as well, i.e., it's referencing the `query.id` column rather than the `tables.id` column.
   
   Also please refer to my comment regarding the chart parameters as we (for right or wrong) doubly define the ID/type tuple.



-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] john-bodley commented on pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on PR #23614:
URL: https://github.com/apache/superset/pull/23614#issuecomment-1499458406

   @hughhhh at Airbnb we're seeing examples of this as well. My question is your fix only includes a migration, i.e., it will remedy any currently ill-defined charts, but there's no fix for actually preventing this again? Has this already been resolved?


-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] hughhhh commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "hughhhh (via GitHub)" <gi...@apache.org>.
hughhhh commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1160271255


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   
   > @hughhhh we're seeing a defined `slices.datasource_name` column when `slices.datasource_type = 'query'` however it doesn't seem to be a dataset in the `tables` table—which would indicate that your migration would likely break said slices when you make the switch from `query` to `table`. BTW where is this query stored?
   
   So those slices are most likely broken, because charts/slices don't know who to execute grabbing data when the datasource_type is `Query`
   
   Query is defined [here](https://github.com/apache/superset/blob/1dd895b9b0ebc2efcd2193b72013b4f9f0183564/superset/models/sql_lab.py#L65)



-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] hughhhh commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "hughhhh (via GitHub)" <gi...@apache.org>.
hughhhh commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1160271255


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   > @hughhhh we're seeing a defined `slices.datasource_name` column when `slices.datasource_type = 'query'` however it doesn't seem to be a dataset in the `tables` table—which would indicate that your migration would likely break said slices when you make the switch from `query` to `table`. BTW where is this query stored?
   
   is the column `datasource_name` only appearing when the `datasource_type` is `query`?
   
   Query is defined [here](https://github.com/apache/superset/blob/1dd895b9b0ebc2efcd2193b72013b4f9f0183564/superset/models/sql_lab.py#L65)



-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] codecov[bot] commented on pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #23614:
URL: https://github.com/apache/superset/pull/23614#issuecomment-1499485283

   ## [Codecov](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#23614](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (3c4d82b) into [master](https://codecov.io/gh/apache/superset/commit/bccd2670cc1d85eeba748ac2cad1ea6fe751473e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (bccd267) will **decrease** coverage by `11.30%`.
   > The diff coverage is `43.37%`.
   
   > :exclamation: Current head 3c4d82b differs from pull request most recent head d552b42. Consider uploading reports for the commit d552b42 to get more accurate results
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #23614       +/-   ##
   ===========================================
   - Coverage   67.64%   56.34%   -11.30%     
   ===========================================
     Files        1916     1918        +2     
     Lines       74036    74116       +80     
     Branches     8039     8051       +12     
   ===========================================
   - Hits        50078    41759     -8319     
   - Misses      21911    30306     +8395     
   - Partials     2047     2051        +4     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | mysql | `?` | |
   | postgres | `?` | |
   | presto | `52.65% <33.78%> (-0.03%)` | :arrow_down: |
   | python | `58.94% <39.18%> (-23.30%)` | :arrow_down: |
   | sqlite | `?` | |
   | unit | `52.62% <39.18%> (-0.03%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...et-frontend/src/dashboard/components/SaveModal.tsx](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2Rhc2hib2FyZC9jb21wb25lbnRzL1NhdmVNb2RhbC50c3g=) | `39.28% <0.00%> (+1.35%)` | :arrow_up: |
   | [superset/commands/importers/v1/examples.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY29tbWFuZHMvaW1wb3J0ZXJzL3YxL2V4YW1wbGVzLnB5) | `0.00% <0.00%> (ø)` | |
   | [superset/constants.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY29uc3RhbnRzLnB5) | `100.00% <ø> (ø)` | |
   | [superset/db\_engine\_specs/postgres.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL3Bvc3RncmVzLnB5) | `72.46% <ø> (-24.64%)` | :arrow_down: |
   | [superset/models/sql\_lab.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvbW9kZWxzL3NxbF9sYWIucHk=) | `70.70% <ø> (-4.30%)` | :arrow_down: |
   | [superset/dashboards/dao.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvZGFzaGJvYXJkcy9kYW8ucHk=) | `34.07% <11.11%> (-62.72%)` | :arrow_down: |
   | [superset/views/core.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvdmlld3MvY29yZS5weQ==) | `36.28% <28.57%> (-38.48%)` | :arrow_down: |
   | [superset/utils/core.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvdXRpbHMvY29yZS5weQ==) | `64.95% <33.33%> (-25.95%)` | :arrow_down: |
   | [superset/charts/post\_processing.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvY2hhcnRzL3Bvc3RfcHJvY2Vzc2luZy5weQ==) | `89.36% <50.00%> (-0.64%)` | :arrow_down: |
   | [superset/dashboards/api.py](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQvZGFzaGJvYXJkcy9hcGkucHk=) | `51.14% <57.14%> (-41.21%)` | :arrow_down: |
   | ... and [9 more](https://codecov.io/gh/apache/superset/pull/23614?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ... and [406 files with indirect coverage changes](https://codecov.io/gh/apache/superset/pull/23614/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] hughhhh merged pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

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


-- 
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-unsubscribe@superset.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org