Skip to content

Commit

Permalink
fix: add missing init on python pkg key_value (#19428)
Browse files Browse the repository at this point in the history
* fix: add missing init on python pkg key_value

* fix lint issues

* fix lint issues
  • Loading branch information
dpgaspar authored Mar 30, 2022
1 parent a8e7624 commit fa35109
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions superset/dashboards/permalink/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def run(self) -> str:
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")
Expand Down
2 changes: 2 additions & 0 deletions superset/explore/permalink/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def run(self) -> str:
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")
Expand Down
16 changes: 16 additions & 0 deletions superset/key_value/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions superset/key_value/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions superset/key_value/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions superset/key_value/commands/upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,11 +97,10 @@ def upsert(self) -> Optional[Key]:
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()
2 changes: 2 additions & 0 deletions tests/integration_tests/key_value/commands/update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/key_value/commands/upsert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()

0 comments on commit fa35109

Please sign in to comment.