Skip to content

Commit 2ec659f

Browse files
authored
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.
1 parent 087ed2e commit 2ec659f

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

ask-sdk-core/ask_sdk_core/attributes_manager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def save_persistent_attributes(self):
222222
def delete_persistent_attributes(self):
223223
# type: () -> None
224224
"""Deletes the persistent attributes from the persistence layer.
225+
225226
:rtype: None
226227
:raises: :py:class: `ask_sdk_core.exceptions.AttributesManagerException`
227228
if trying to delete persistence attributes without persistence adapter
@@ -230,8 +231,8 @@ def delete_persistent_attributes(self):
230231
raise AttributesManagerException(
231232
"Cannot delete PersistentAttributes without "
232233
"persistence adapter!")
233-
if self._persistent_attributes_set:
234-
self._persistence_adapter.delete_attributes(
235-
request_envelope=self._request_envelope)
236-
self._persistence_attributes = {}
237-
self._persistent_attributes_set = False
234+
235+
self._persistence_adapter.delete_attributes(
236+
request_envelope=self._request_envelope)
237+
self._persistence_attributes = {}
238+
self._persistent_attributes_set = False

ask-sdk-core/tests/unit/test_attributes_manager.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,4 @@ def test_delete_persistent_attributes(self):
262262

263263
assert attributes_manager._persistence_adapter.attributes == {}, (
264264
"AttributesManager fails to delete persistent attributes via "
265-
"persistence adapter")
266-
267-
def test_delete_persistent_attributes_with_calling_delete_persistent_attributes_multiple_times(self):
268-
session = Session()
269-
request_envelope = RequestEnvelope(
270-
version=None, session=session, context=None, request=None)
271-
attributes_manager = AttributesManager(
272-
request_envelope=request_envelope,
273-
persistence_adapter=MockPersistenceAdapter())
274-
275-
attributes_manager.persistent_attributes = {"key": "value"}
276-
277-
attributes_manager.delete_persistent_attributes()
278-
attributes_manager.delete_persistent_attributes()
279-
attributes_manager.delete_persistent_attributes()
280-
attributes_manager.delete_persistent_attributes()
281-
282-
assert attributes_manager._persistence_adapter.del_count == 1, (
283-
"AttributesManager should make only 1 delete_attributes call "
284-
"during multiple delete_persistent_attributes calls")
265+
"persistence adapter")

docs/en/ATTRIBUTES.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,12 @@ Interface
132132
133133
def save_persistent_attributes(self):
134134
# type: () -> None
135-
# Persistence Attributes save
136-
# Save the Persistence adapter to save the attributes
135+
# Save the persistence attributes to the persistence layer
136+
....
137+
138+
def delete_persistent_attributes(self):
139+
# type: () -> None
140+
# Delete the persistence attributes from the persistence layer
137141
....
138142
139143
@@ -162,6 +166,12 @@ attributes.
162166
``save_persistent_attributes()`` to save persistent attributes to the
163167
persistence layer.
164168

169+
.. note::
170+
171+
The ``delete_attributes`` on the default ``DynamoDbPersistenceAdapter``
172+
implementation will delete the persistence attributes from local cache
173+
as well as from the persistence layer (DynamoDb table).
174+
165175

166176
PersistenceAdapter
167177
==================

docs/ja/ATTRIBUTES.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ AttributesManagerには、ハンドラーで取得や更新を行えるアトリ
110110
111111
def save_persistent_attributes(self):
112112
# type: () -> None
113-
# Persistence Attributes save
114-
# Save the Persistence adapter to save the attributes
113+
# Save the persistence attributes to the persistence layer
114+
....
115+
116+
def delete_persistent_attributes(self):
117+
# type: () -> None
118+
# Delete the persistence attributes from the persistence layer
115119
....
116120
117121
@@ -129,3 +133,17 @@ AttributesManagerには、ハンドラーで取得や更新を行えるアトリ
129133
persistence_attr['foo'] = 'baz'
130134
handler_input.attributes_manager.save_persistent_attributes()
131135
return handler_input.response_builder.response
136+
137+
.. note::
138+
139+
スキルのパフォーマンスを向上させるために、 `` AttributesManager``は永続的なオブジェクトをキャッシュします。
140+
ローカルに属性。 `` persistent_attributes``セッターは
141+
ローカルにキャッシュされた永続属性電話する必要があります
142+
`` save_persistent_attributes() ``に永続属性を保存する
143+
永続層。
144+
145+
.. note::
146+
147+
デフォルトの ``DynamoDbPersistenceAdapter``の`` delete_attributes``
148+
実装はローカルキャッシュから永続属性を削除します
149+
持続層(DynamoDbテーブル)からも同様です。

0 commit comments

Comments
 (0)