From 2ec659f3487132e5000dc85095c094102c619462 Mon Sep 17 00:00:00 2001 From: Nikhil Yogendra Murali <25237515+nikhilym@users.noreply.github.com> Date: Tue, 11 Jun 2019 13:49:20 -0700 Subject: [PATCH] Delete persistence attributes without checking setter (#99) This commit fixes the delete persistence attributes method call in attributes manager to call the delete item method even if the persistence attributes set boolean is not available. Since delete item is idempotent and there might be cases where skill devs might have to delete the attributes even before retrieving them, this needs to be fixed. The commit also adds the documentation for delete attributes call. --- .../ask_sdk_core/attributes_manager.py | 11 +++++----- .../tests/unit/test_attributes_manager.py | 21 +----------------- docs/en/ATTRIBUTES.rst | 14 ++++++++++-- docs/ja/ATTRIBUTES.rst | 22 +++++++++++++++++-- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/ask-sdk-core/ask_sdk_core/attributes_manager.py b/ask-sdk-core/ask_sdk_core/attributes_manager.py index 3397f22..737eb25 100644 --- a/ask-sdk-core/ask_sdk_core/attributes_manager.py +++ b/ask-sdk-core/ask_sdk_core/attributes_manager.py @@ -222,6 +222,7 @@ def save_persistent_attributes(self): def delete_persistent_attributes(self): # type: () -> None """Deletes the persistent attributes from the persistence layer. + :rtype: None :raises: :py:class: `ask_sdk_core.exceptions.AttributesManagerException` if trying to delete persistence attributes without persistence adapter @@ -230,8 +231,8 @@ def delete_persistent_attributes(self): raise AttributesManagerException( "Cannot delete PersistentAttributes without " "persistence adapter!") - if self._persistent_attributes_set: - self._persistence_adapter.delete_attributes( - request_envelope=self._request_envelope) - self._persistence_attributes = {} - self._persistent_attributes_set = False + + self._persistence_adapter.delete_attributes( + request_envelope=self._request_envelope) + self._persistence_attributes = {} + self._persistent_attributes_set = False diff --git a/ask-sdk-core/tests/unit/test_attributes_manager.py b/ask-sdk-core/tests/unit/test_attributes_manager.py index 92848a1..5266462 100644 --- a/ask-sdk-core/tests/unit/test_attributes_manager.py +++ b/ask-sdk-core/tests/unit/test_attributes_manager.py @@ -262,23 +262,4 @@ def test_delete_persistent_attributes(self): assert attributes_manager._persistence_adapter.attributes == {}, ( "AttributesManager fails to delete persistent attributes via " - "persistence adapter") - - def test_delete_persistent_attributes_with_calling_delete_persistent_attributes_multiple_times(self): - session = Session() - request_envelope = RequestEnvelope( - version=None, session=session, context=None, request=None) - attributes_manager = AttributesManager( - request_envelope=request_envelope, - persistence_adapter=MockPersistenceAdapter()) - - attributes_manager.persistent_attributes = {"key": "value"} - - attributes_manager.delete_persistent_attributes() - attributes_manager.delete_persistent_attributes() - attributes_manager.delete_persistent_attributes() - attributes_manager.delete_persistent_attributes() - - assert attributes_manager._persistence_adapter.del_count == 1, ( - "AttributesManager should make only 1 delete_attributes call " - "during multiple delete_persistent_attributes calls") \ No newline at end of file + "persistence adapter") \ No newline at end of file diff --git a/docs/en/ATTRIBUTES.rst b/docs/en/ATTRIBUTES.rst index 597dc3a..ec37e14 100644 --- a/docs/en/ATTRIBUTES.rst +++ b/docs/en/ATTRIBUTES.rst @@ -132,8 +132,12 @@ Interface def save_persistent_attributes(self): # type: () -> None - # Persistence Attributes save - # Save the Persistence adapter to save the attributes + # Save the persistence attributes to the persistence layer + .... + + def delete_persistent_attributes(self): + # type: () -> None + # Delete the persistence attributes from the persistence layer .... @@ -162,6 +166,12 @@ attributes. ``save_persistent_attributes()`` to save persistent attributes to the persistence layer. +.. note:: + + The ``delete_attributes`` on the default ``DynamoDbPersistenceAdapter`` + implementation will delete the persistence attributes from local cache + as well as from the persistence layer (DynamoDb table). + PersistenceAdapter ================== diff --git a/docs/ja/ATTRIBUTES.rst b/docs/ja/ATTRIBUTES.rst index 40e5703..498313c 100644 --- a/docs/ja/ATTRIBUTES.rst +++ b/docs/ja/ATTRIBUTES.rst @@ -110,8 +110,12 @@ AttributesManagerには、ハンドラーで取得や更新を行えるアトリ def save_persistent_attributes(self): # type: () -> None - # Persistence Attributes save - # Save the Persistence adapter to save the attributes + # Save the persistence attributes to the persistence layer + .... + + def delete_persistent_attributes(self): + # type: () -> None + # Delete the persistence attributes from the persistence layer .... @@ -129,3 +133,17 @@ AttributesManagerには、ハンドラーで取得や更新を行えるアトリ persistence_attr['foo'] = 'baz' handler_input.attributes_manager.save_persistent_attributes() return handler_input.response_builder.response + +.. note:: + + スキルのパフォーマンスを向上させるために、 `` AttributesManager``は永続的なオブジェクトをキャッシュします。 + ローカルに属性。 `` persistent_attributes``セッターは + ローカルにキャッシュされた永続属性電話する必要があります + `` save_persistent_attributes() ``に永続属性を保存する + 永続層。 + +.. note:: + + デフォルトの ``DynamoDbPersistenceAdapter``の`` delete_attributes`` + 実装はローカルキャッシュから永続属性を削除します + 持続層(DynamoDbテーブル)からも同様です。 \ No newline at end of file