Merge lp:~azzar1/software-properties/fix-1818992 into lp:software-properties

Proposed by Andrea Azzarone on 2019-03-07
Status: Merged
Approved by: Sebastien Bacher on 2019-03-14
Approved revision: 1079
Merged at revision: 1079
Proposed branch: lp:~azzar1/software-properties/fix-1818992
Merge into: lp:software-properties
Diff against target: 56 lines (+16/-5)
1 file modified
softwareproperties/GoaAuth.py (+16/-5)
To merge this branch: bzr merge lp:~azzar1/software-properties/fix-1818992
Reviewer Review Type Date Requested Status
Sebastien Bacher 2019-03-07 Approve on 2019-03-14
Review via email: mp+364112@code.launchpad.net

Commit message

Don't segfault if GoaClient.new fails. Also make it async to not block the UI.

To post a comment you must log in.
Sebastien Bacher (seb128) wrote :

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwareproperties/GoaAuth.py'
2--- softwareproperties/GoaAuth.py 2018-04-17 11:36:55 +0000
3+++ softwareproperties/GoaAuth.py 2019-03-07 18:28:33 +0000
4@@ -21,7 +21,9 @@
5
6 import gi
7 gi.require_version('Goa', '1.0')
8-from gi.repository import Gio, Goa, GObject
9+from gi.repository import Gio, GLib, Goa, GObject
10+
11+import logging
12
13 class GoaAuth(GObject.GObject):
14
15@@ -32,12 +34,21 @@
16 def __init__(self):
17 GObject.GObject.__init__(self)
18
19- self.goa_client = Goa.Client.new_sync(None)
20 self.account = None
21+ self.cancellable = Gio.Cancellable()
22+ Goa.Client.new(self.cancellable, self._on_goa_client_ready)
23
24 self.settings = Gio.Settings.new('com.ubuntu.SoftwareProperties')
25 self.settings.connect('changed::goa-account-id', self._on_settings_changed)
26- self._load()
27+
28+ def _on_goa_client_ready(self, source, res):
29+ try:
30+ self.goa_client = Goa.Client.new_finish(res)
31+ except GLib.Error as e:
32+ logging.error('Failed to get a Gnome Online Account: {}'.format(e.message))
33+ self.goa_client = None
34+ else:
35+ self._load()
36
37 def login(self, account):
38 assert(account)
39@@ -50,7 +61,7 @@
40
41 @GObject.Property
42 def token(self):
43- if self.account is None:
44+ if self.account is None or self.goa_client is None:
45 return None
46
47 obj = self.goa_client.lookup_by_id(self.account.props.id)
48@@ -64,7 +75,7 @@
49 return pbased.call_get_password_sync('livepatch')
50
51 def _update_state_from_account_id(self, account_id):
52- if account_id:
53+ if account_id and self.goa_client is not None:
54 # Make sure the account-id is valid
55 obj = self.goa_client.lookup_by_id(account_id)
56 if obj is None:

Subscribers

People subscribed via source and target branches

to status/vote changes: