Skip to content

Commit

Permalink
Delete persistence attributes without checking setter (#99)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikhilym authored Jun 11, 2019
1 parent 087ed2e commit 2ec659f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
11 changes: 6 additions & 5 deletions ask-sdk-core/ask_sdk_core/attributes_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
21 changes: 1 addition & 20 deletions ask-sdk-core/tests/unit/test_attributes_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
"persistence adapter")
14 changes: 12 additions & 2 deletions docs/en/ATTRIBUTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
....
Expand Down Expand Up @@ -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
==================
Expand Down
22 changes: 20 additions & 2 deletions docs/ja/ATTRIBUTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
....
Expand All @@ -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テーブル)からも同様です。

0 comments on commit 2ec659f

Please sign in to comment.