Merge lp:~zyga/checkbox/fix-1412660 into lp:checkbox

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 3536
Merged at revision: 3536
Proposed branch: lp:~zyga/checkbox/fix-1412660
Merge into: lp:checkbox
Diff against target: 17 lines (+6/-1)
1 file modified
checkbox-ng/checkbox_ng/service.py (+6/-1)
To merge this branch: bzr merge lp:~zyga/checkbox/fix-1412660
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+247002@code.launchpad.net

Description of the change

7e7ea2b checkbox-ng:service: fix .via for jobs not in session

To post a comment you must log in.
lp:~zyga/checkbox/fix-1412660 updated
3536. By Zygmunt Krynicki

checkbox-ng:service: fix .via for jobs not in session

This patch fixes a crash when JobDefinitionWrapper.via was being
accessed after resuming a session, when the corresponding job was not
being a part of the session (but is still available on DBus via a
provider). For example:
 - create a provider with jobs [a, b]
 - create a session with job [a]
 - save the session before a runs
 - resume the session, the session now has [a] but not [b] in it
 - attempt to access b.via

In the current code, this would crash as there was an implicit,
incorrect assumption that each job visible on DBus is also a part of the
current session. The patch corrects that assumption by allowing no
JobState to exist for any JobDefinition.

(A copy of the relevant comment on the bug corresponding report)

1) Job definitions are either generated (and thus bound to a session) or
   not (and thus bound to a provider)
2) The .via property was previously a mutable state on a job. Now it is
   something one can access from session-bound JobState.
   2a) this means that .via cannot be accessed before a session exists
   2b) this means that .via cannot be accessed if a session doesn't
       contain a given job (despite that job existing).

In the past, via was always accessible, perhaps holding nothing or
perhaps holding stale data (from previous session run). Currently when
2b happens, we crash.

The fix is to simply return "" when there is no session or there
is no corresponding JobState in the session.

Fixes: https://bugs.launchpad.net/checkbox-ng/+bug/1412660
Signed-off-by: Zygmunt Krynicki <email address hidden>

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

That's indeed what the service must return if the job is not yet in the state map.
Thanks for the detailed investigation.

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-ng/checkbox_ng/service.py'
2--- checkbox-ng/checkbox_ng/service.py 2015-01-07 14:52:42 +0000
3+++ checkbox-ng/checkbox_ng/service.py 2015-01-20 13:07:53 +0000
4@@ -373,7 +373,12 @@
5 session_obj = ServiceWrapper.get_session_obj()
6 if session_obj is None:
7 return ""
8- state = session_obj.job_state_map[self.native.id]
9+ try:
10+ state = session_obj.job_state_map[self.native.id]
11+ except KeyError:
12+ # See: LP: #1412660, session_obj can be None and event if it isn't,
13+ # session_obj.job_state_map might *not* have self.native.id in it.
14+ return ""
15 if state.via_job is None:
16 return ""
17 return state.via_job.checksum

Subscribers

People subscribed via source and target branches