You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2022/04/04 08:22:12 UTC

[superset] 03/24: fix: add missing init on python pkg key_value (#19428)

This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to tag 1.5.0rc1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 7aba89c486e58a94df99ca3a12da946d4a0eb5b9
Author: Daniel Vaz Gaspar <da...@gmail.com>
AuthorDate: Wed Mar 30 12:46:42 2022 +0100

    fix: add missing init on python pkg key_value (#19428)
    
    * fix: add missing init on python pkg key_value
    
    * fix lint issues
    
    * fix lint issues
    
    (cherry picked from commit fa35109bf2a416462e3c83f527aa82c20b67818d)
---
 superset/dashboards/permalink/commands/create.py         |  2 ++
 superset/explore/permalink/commands/create.py            |  2 ++
 superset/key_value/commands/__init__.py                  | 16 ++++++++++++++++
 superset/key_value/commands/create.py                    |  1 +
 superset/key_value/commands/update.py                    |  1 +
 superset/key_value/commands/upsert.py                    | 16 ++++++++--------
 .../integration_tests/key_value/commands/update_test.py  |  2 ++
 .../integration_tests/key_value/commands/upsert_test.py  |  3 +++
 8 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/superset/dashboards/permalink/commands/create.py b/superset/dashboards/permalink/commands/create.py
index 27ddf0534d..4ffd41104e 100644
--- a/superset/dashboards/permalink/commands/create.py
+++ b/superset/dashboards/permalink/commands/create.py
@@ -53,6 +53,8 @@ class CreateDashboardPermalinkCommand(BaseDashboardPermalinkCommand):
                 resource=self.resource,
                 value=value,
             ).run()
+            if key.id is None:
+                raise DashboardPermalinkCreateFailedError("Unexpected missing key id")
             return encode_permalink_key(key=key.id, salt=self.salt)
         except SQLAlchemyError as ex:
             logger.exception("Error running create command")
diff --git a/superset/explore/permalink/commands/create.py b/superset/explore/permalink/commands/create.py
index 55fb0820cd..c09ca3b372 100644
--- a/superset/explore/permalink/commands/create.py
+++ b/superset/explore/permalink/commands/create.py
@@ -53,6 +53,8 @@ class CreateExplorePermalinkCommand(BaseExplorePermalinkCommand):
                 value=value,
             )
             key = command.run()
+            if key.id is None:
+                raise ExplorePermalinkCreateFailedError("Unexpected missing key id")
             return encode_permalink_key(key=key.id, salt=self.salt)
         except SQLAlchemyError as ex:
             logger.exception("Error running create command")
diff --git a/superset/key_value/commands/__init__.py b/superset/key_value/commands/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/superset/key_value/commands/__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.
diff --git a/superset/key_value/commands/create.py b/superset/key_value/commands/create.py
index 613fabcdeb..5125ce7b01 100644
--- a/superset/key_value/commands/create.py
+++ b/superset/key_value/commands/create.py
@@ -39,6 +39,7 @@ class CreateKeyValueCommand(BaseCommand):
     key: Optional[Union[int, UUID]]
     expires_on: Optional[datetime]
 
+    # pylint: disable=too-many-arguments
     def __init__(
         self,
         resource: KeyValueResource,
diff --git a/superset/key_value/commands/update.py b/superset/key_value/commands/update.py
index 7333b48c5c..48fd8daa8a 100644
--- a/superset/key_value/commands/update.py
+++ b/superset/key_value/commands/update.py
@@ -41,6 +41,7 @@ class UpdateKeyValueCommand(BaseCommand):
     key: Union[int, UUID]
     expires_on: Optional[datetime]
 
+    # pylint: disable=too-many-argumentsåå
     def __init__(
         self,
         resource: KeyValueResource,
diff --git a/superset/key_value/commands/upsert.py b/superset/key_value/commands/upsert.py
index aa495f7cc7..8fd0bd240f 100644
--- a/superset/key_value/commands/upsert.py
+++ b/superset/key_value/commands/upsert.py
@@ -42,6 +42,7 @@ class UpsertKeyValueCommand(BaseCommand):
     key: Union[int, UUID]
     expires_on: Optional[datetime]
 
+    # pylint: disable=too-many-arguments
     def __init__(
         self,
         resource: KeyValueResource,
@@ -96,11 +97,10 @@ class UpsertKeyValueCommand(BaseCommand):
             db.session.merge(entry)
             db.session.commit()
             return Key(entry.id, entry.uuid)
-        else:
-            return CreateKeyValueCommand(
-                resource=self.resource,
-                value=self.value,
-                actor=self.actor,
-                key=self.key,
-                expires_on=self.expires_on,
-            ).run()
+        return CreateKeyValueCommand(
+            resource=self.resource,
+            value=self.value,
+            actor=self.actor,
+            key=self.key,
+            expires_on=self.expires_on,
+        ).run()
diff --git a/tests/integration_tests/key_value/commands/update_test.py b/tests/integration_tests/key_value/commands/update_test.py
index 62a8126ba2..3b24ecdf0a 100644
--- a/tests/integration_tests/key_value/commands/update_test.py
+++ b/tests/integration_tests/key_value/commands/update_test.py
@@ -53,6 +53,7 @@ def test_update_id_entry(
         key=ID_KEY,
         value=NEW_VALUE,
     ).run()
+    assert key is not None
     assert key.id == ID_KEY
     entry = db.session.query(KeyValueEntry).filter_by(id=ID_KEY).autoflush(False).one()
     assert pickle.loads(entry.value) == NEW_VALUE
@@ -73,6 +74,7 @@ def test_update_uuid_entry(
         key=UUID_KEY,
         value=NEW_VALUE,
     ).run()
+    assert key is not None
     assert key.uuid == UUID_KEY
     entry = (
         db.session.query(KeyValueEntry).filter_by(uuid=UUID_KEY).autoflush(False).one()
diff --git a/tests/integration_tests/key_value/commands/upsert_test.py b/tests/integration_tests/key_value/commands/upsert_test.py
index adb652e66a..1970a1fc2c 100644
--- a/tests/integration_tests/key_value/commands/upsert_test.py
+++ b/tests/integration_tests/key_value/commands/upsert_test.py
@@ -53,6 +53,7 @@ def test_upsert_id_entry(
         key=ID_KEY,
         value=NEW_VALUE,
     ).run()
+    assert key is not None
     assert key.id == ID_KEY
     entry = (
         db.session.query(KeyValueEntry).filter_by(id=int(ID_KEY)).autoflush(False).one()
@@ -75,6 +76,7 @@ def test_upsert_uuid_entry(
         key=UUID_KEY,
         value=NEW_VALUE,
     ).run()
+    assert key is not None
     assert key.uuid == UUID_KEY
     entry = (
         db.session.query(KeyValueEntry).filter_by(uuid=UUID_KEY).autoflush(False).one()
@@ -93,6 +95,7 @@ def test_upsert_missing_entry(app_context: AppContext, admin: User) -> None:
         key=456,
         value=NEW_VALUE,
     ).run()
+    assert key is not None
     assert key.id == 456
     db.session.query(KeyValueEntry).filter_by(id=456).delete()
     db.session.commit()