Skip to content

Commit b49d9f3

Browse files
committed
Make settings dataclasses resilient towards new settings being added
Turns out during version 2.0 development new `loopback` settings were added. Since we want to be compatible with many versions of NetworkManager it is good to be able to handle new settings types being added that have not yet been added to binds.
1 parent 85d42bc commit b49d9f3

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

sdbus_async/networkmanager/settings/profile.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,16 @@ def from_dbus(cls, dbus_dict: NetworkManagerConnectionProperties
410410
if group:
411411
for key in ("addresses", "routes"):
412412
group.pop(key, None)
413-
try:
414-
unvarianted_options: Dict[str, Any] = {
415-
SETTING_DBUS_NAME_TO_NAME[k]: SETTING_TO_CLASS[k].from_dbus(v)
416-
for k, v in dbus_dict.items()}
417-
except KeyError as e:
418-
print(dbus_dict)
419-
raise e
413+
414+
unvarianted_options: Dict[str, Any] = {}
415+
for k, v in dbus_dict.items():
416+
try:
417+
unvarianted_options[SETTING_DBUS_NAME_TO_NAME[k]] = (
418+
SETTING_TO_CLASS[k].from_dbus(v)
419+
)
420+
except KeyError:
421+
...
422+
420423
return cls(**unvarianted_options)
421424

422425
@classmethod

tools/jinja_templates/profile.py.jinja2

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,16 @@ class ConnectionProfile:
112112
if group:
113113
for key in ("addresses", "routes"):
114114
group.pop(key, None)
115-
try:
116-
unvarianted_options: Dict[str, Any] = {
117-
SETTING_DBUS_NAME_TO_NAME[k]: SETTING_TO_CLASS[k].from_dbus(v)
118-
for k, v in dbus_dict.items()}
119-
except KeyError as e:
120-
print(dbus_dict)
121-
raise e
115+
116+
unvarianted_options: Dict[str, Any] = {}
117+
for k, v in dbus_dict.items():
118+
try:
119+
unvarianted_options[SETTING_DBUS_NAME_TO_NAME[k]] = (
120+
SETTING_TO_CLASS[k].from_dbus(v)
121+
)
122+
except KeyError:
123+
...
124+
122125
return cls(**unvarianted_options)
123126

124127
@classmethod

0 commit comments

Comments
 (0)