Skip to content

Commit 3fde27b

Browse files
Flaw data reset corner case - part 1 (#947)
This PR: * minor - creates the linkage between the updated model and the sync manager right upon schedule if possible so the conflicting sync managers check won't have a blind spot during the period between the sync managers creation and the first execution * removes the redundant workflow update after the successful sync into Jira so there are no data overwrites (e.g. transition manager which syncs PRE_SECONDARY_ASSESSMENT finishes earlier than transition manager which syncs TRIAGE), this is unfortunately still imperfect as the Flaw data reset won't now happen directly in OSIDB but can still happen in Jira (e.g. PRE_SECONDARY_ASSESSMENT is written earlier than TRIAGE and TRIAGE then overwrites it) which will eventually be downloaded back to OSIDB, to fix this, we need to implement solution proposed in OSIDB-4175 * moves ACL adjustment upon workflow advancing as it should happen right away when we do advance the workflow in OSIDB and not to wait until we sync it into Jira, this seems like a remaining part from the synchronous task manager Closes OSIDB-4136
2 parents 14e9f6d + 51833f7 commit 3fde27b

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ jobs:
8181
python3-pytest-cov
8282
python3.9
8383
python36
84-
python38
8584
redhat-rpm-config
8685
rpm-build
8786
rpmlint

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"filename": ".github/workflows/test.yml",
135135
"hashed_secret": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
136136
"is_verified": false,
137-
"line_number": 93,
137+
"line_number": 92,
138138
"is_secret": false
139139
}
140140
],
@@ -475,5 +475,5 @@
475475
}
476476
]
477477
},
478-
"generated_at": "2025-03-25T17:43:50Z"
478+
"generated_at": "2025-04-23T08:18:22Z"
479479
}

apps/taskman/tests/test_flaw_model_integration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,23 @@ def mock_transition_task(self, jira_token=None):
402402
# flaw change and workflow state change at once
403403
assert create_or_update_performed
404404
assert transition_performed
405+
406+
def test_workflow_transition_not_overwriting(self, monkeypatch):
407+
""" """
408+
409+
def mock_transition_task(self, flaw: Flaw, check_token: bool = True):
410+
# simulate Flaw being updated in some other process instead
411+
Flaw.objects.filter(uuid=flaw.uuid).update(
412+
workflow_state="PRE_SECONDARY_ASSESSMENT"
413+
)
414+
415+
monkeypatch.setattr(JiraTaskmanQuerier, "transition_task", mock_transition_task)
416+
417+
flaw = FlawFactory(workflow_state="TRIAGE")
418+
flaw._transition_task()
419+
# check that workflow state is the same as the transition began with
420+
assert flaw.workflow_state == "TRIAGE"
421+
422+
flaw.refresh_from_db()
423+
# check that the change to the workflow state by other process wasn't overwritten
424+
assert flaw.workflow_state == "PRE_SECONDARY_ASSESSMENT"

collectors/jiraffe/tests/test_collectors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ def mock_get_issue(self, jira_id: str, expand: str):
163163

164164
# 5 - simulate user promoting a flaw
165165
flaw.workflow_state = WorkflowModel.WorkflowState.TRIAGE
166+
flaw.save(auto_timestamps=False)
166167
# provide a fake diff just to pretend that the workflow state has changed
167168
flaw.tasksync(diff={"workflow_state": None}, jira_token=jira_token)
168169
flaw = Flaw.objects.get(uuid=flaw.uuid)

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- Add feedback form to tracker description (OSIDB-4095)
1010

11+
### Changed
12+
- Adjust ACLs upon workflow advancement in OSIDB and do not wait for Jira sync (OSIDB-4136)
13+
1114
### Fixed
1215
- Postpone Jira task download when there are sync or transition managers pending (OSIDB-4136)
1316
- Consider affect in AFFECTED/DELEGATED state as not resolved (OSIDB-4137)
1417
- Fix missing include_history field on Affect and Flaw API documentation (OSIDB-3960)
18+
- Remove redundant Flaw workflow update (OSIDB-4136)
1519

1620
## [4.10.0] - 2025-03-25
1721
### Fixed

osidb/models/flaw/flaw.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,13 @@ def tasksync(
10711071
JiraTaskSyncManager.schedule(str(self.uuid))
10721072

10731073
if transition_task:
1074+
# workflow transition may result in ACL change
1075+
self.adjust_acls(save=False)
1076+
Flaw.objects.filter(uuid=self.uuid).update(
1077+
acl_read=self.acl_read,
1078+
acl_write=self.acl_write,
1079+
)
1080+
10741081
JiraTaskTransitionManager.check_for_reschedules()
10751082
JiraTaskTransitionManager.schedule(str(self.uuid))
10761083

@@ -1079,6 +1086,13 @@ def tasksync(
10791086
self._create_or_update_task(jira_token)
10801087

10811088
if transition_task:
1089+
# workflow transition may result in ACL change
1090+
self.adjust_acls(save=False)
1091+
Flaw.objects.filter(uuid=self.uuid).update(
1092+
acl_read=self.acl_read,
1093+
acl_write=self.acl_write,
1094+
)
1095+
10821096
self._transition_task(jira_token)
10831097

10841098
def _create_or_update_task(self, jira_token=None):
@@ -1111,14 +1125,6 @@ def _transition_task(self, jira_token=None):
11111125
jtq = JiraTaskmanQuerier(token=jira_token)
11121126

11131127
jtq.transition_task(self)
1114-
# workflow transition may result in ACL change
1115-
self.adjust_acls(save=False)
1116-
Flaw.objects.filter(uuid=self.uuid).update(
1117-
acl_read=self.acl_read,
1118-
acl_write=self.acl_write,
1119-
workflow_name=self.workflow_name,
1120-
workflow_state=self.workflow_state,
1121-
)
11221128

11231129
download_manager = models.ForeignKey(
11241130
FlawDownloadManager, null=True, blank=True, on_delete=models.CASCADE

osidb/sync_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def schedule(cls, sync_id, *args, schedule_options=None, **kwargs):
8888
cls.objects.get_or_create(sync_id=sync_id)
8989
cls.objects.filter(sync_id=sync_id).update(last_scheduled_dt=timezone.now())
9090

91+
# Create model linkage if possible to make checking for conflicting
92+
# sync managers possible
93+
manager = cls.objects.get(sync_id=sync_id)
94+
manager.update_synced_links()
95+
9196
def schedule_task():
9297
try:
9398
cls.sync_task.apply_async(

0 commit comments

Comments
 (0)