Skip to content

Commit c275bf4

Browse files
committed
fixes
1 parent 8abecb7 commit c275bf4

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

server/plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,15 @@ def process_plugin_events(db, plugin, plugEventsArr):
817817
pluginObjects.append(tmpObjFromEvent)
818818
# update data of existing objects
819819
else:
820-
if tmpObjFromEvent.status == "watched-changed":
821-
changed_this_cycle.add(tmpObjFromEvent.idsHash)
822-
823820
index = 0
824821
for plugObj in pluginObjects:
825822
# find corresponding object for the event and merge
826823
if plugObj.idsHash == tmpObjFromEvent.idsHash:
824+
if (
825+
plugObj.status == "missing-in-last-scan"
826+
or tmpObjFromEvent.status == "watched-changed"
827+
):
828+
changed_this_cycle.add(tmpObjFromEvent.idsHash)
827829
pluginObjects[index] = combine_plugin_objects(
828830
plugObj, tmpObjFromEvent
829831
)

test/server/test_plugin_history_filtering.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,26 @@ def test_objects_table_still_updated_for_unchanged(self, plugin_db, monkeypatch)
211211

212212
objs = plugin_objects_rows(conn, PREFIX)
213213
assert len(objs) == 1, "Plugins_Objects should still have the object"
214+
215+
def test_recovery_from_missing_recorded(self, plugin_db, monkeypatch):
216+
"""An object that was missing-in-last-scan and reappears (even with
217+
unchanged watched values) should produce a history row."""
218+
db, conn = plugin_db
219+
monkeypatch.setattr("plugin.get_setting_value", _no_report_on)
220+
221+
cur = conn.cursor()
222+
seed_plugin_object(cur, PREFIX, "device_A", watched1="val1",
223+
status="missing-in-last-scan")
224+
conn.commit()
225+
226+
plugin = make_plugin_dict(PREFIX)
227+
# device_A reappears with the same watched value
228+
events = [make_plugin_event_row(PREFIX, "device_A", watched1="val1")]
229+
230+
process_plugin_events(db, plugin, events)
231+
232+
rows = plugin_history_rows(conn, PREFIX)
233+
assert len(rows) == 1, (
234+
"recovery from missing-in-last-scan should generate a history row"
235+
)
236+
assert rows[0][2] == "device_A"

0 commit comments

Comments
 (0)