Skip to content

Commit b206b23

Browse files
committed
TaskWithState.process_get_state(), any changes to process_data now ignored
#14 And docs: #13
1 parent 7034f2c commit b206b23

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## Changed
11+
12+
- In `TaskWithState.process_get_state()` any changes to `process_data` are now ignored. https://github.com/OpenDataServices/lib-cove-web-2/issues/14
13+
1014
## [0.3.0] - 2023-09-14
1115

1216
When upgrading to this version, `ALLOWED_UNKNOWN_CONTENT_TYPES` must be set in the Django settings file, ideally from the settings file included with this library.

libcoveweb2/process/common_tasks/task_with_state.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
class TaskWithState(ProcessDataTask):
1111
"""An abstract task that helps you save state from
1212
the processing step and add it to the context.
13+
14+
It will cache one JSON blob for you, and add
15+
it to the view context when a user is looking at the results.
16+
(So make sure you choose keys in the JSON blob carefully
17+
so as not to clash with other view context variables!)
18+
1319
Extend and provide your own state_filename and process_get_state.
1420
"""
1521

1622
#: Set state_filename to a unique name for each task.
1723
#:
18-
#: If you change this name the task will be rerun, so this is is a good way to
24+
#: If you change this name the task will be rerun, so this is a good way to
1925
#: make sure all underlying data changes if a new version of this bit of cove
2026
#: is released.
2127
state_filename: str = "task_with_state.json"
@@ -28,14 +34,19 @@ def process_get_state(self, process_data: dict):
2834
2935
Should return a tuple.
3036
The first item is the results to save, as a dictionary.
31-
The second item is process_data, as a dictionary."""
37+
The second item is process_data, as a dictionary.
38+
39+
Do NOT change process_data in this function!
40+
The fact it's returned is a mistake:
41+
https://github.com/OpenDataServices/lib-cove-web-2/issues/14
42+
"""
3243
return {}, process_data
3344

3445
def process(self, process_data: dict) -> dict:
3546
if self.does_state_exist():
3647
return process_data
3748

38-
state, process_data = self.process_get_state(process_data)
49+
state, process_data_throw_away = self.process_get_state(process_data)
3950

4051
default_storage.save(
4152
os.path.join(self.supplied_data.storage_dir(), self.state_filename),

0 commit comments

Comments
 (0)