@@ -29,7 +29,8 @@ def parse_history(self, response, item, history_page=1):
2929 self .logger .info (f"Reviewing Page { item ['page_id' ]} history" )
3030
3131 page_id = item ["page_id" ]
32- changes = item ["history" ] if "history" in item else {}
32+ changes = item .get ("history" , {})
33+ item ["history" ] = changes # Ensure history key always exists
3334
3435 try :
3536 response_text = getattr (response , "text" , "" ) or ""
@@ -116,11 +117,13 @@ def parse_history(self, response, item, history_page=1):
116117 self .logger .exception ("Could not process row." )
117118 self .logger .error (row )
118119
119- item ["history" ] = changes
120- # The "0" change is the first revision, and the last one that shows up.
121- # If we have it then we're done.
122- if "0" in changes :
123- return self .get_page_source_request (page_id , item )
120+ # Update item history after processing all rows
121+ item ["history" ] = changes
122+
123+ # The "0" change is the first revision, and the last one that shows up.
124+ # If we have it then we're done.
125+ if "0" in changes :
126+ return self .get_page_source_request (page_id , item )
124127
125128 next_page = history_page + 1
126129 if next_page > MAX_HISTORY_PAGES :
0 commit comments