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
This commit is contained in:
parent
a8e7624eb5
commit
fa35109bf2
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue