Skip to content

Commit 69874e5

Browse files
committed
Fix connection settings being optional
ConnectionSettings must always be present in connection profile.
1 parent ea21b2a commit 69874e5

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

sdbus_async/networkmanager/settings/profile.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,7 @@ class ConnectionProfile:
9696
A group of related key/value pairs describing a specific piece
9797
of a Connection (profile). Keys are also referred to as properties.
9898
"""
99-
# The settings object "connection" is special: It must always be present
100-
# because it contains the UUID and the connection type which are required:
101-
connection: ConnectionSettings = field(
102-
metadata={'dbus_name': 'connection',
103-
'settings_class': ConnectionSettings},
104-
)
105-
# The list of the remaining settings classes was generated by
99+
# The list of the settings classes was generated by
106100
# tools/generate-settings-dataclasses-jinja.py which generates the
107101
# settings classes themselfes as well.
108102
# If possible, please make changes by also updating the script.
@@ -143,10 +137,10 @@ class ConnectionProfile:
143137
'settings_class': CdmaSettings},
144138
default=None,
145139
)
146-
connection: Optional[ConnectionSettings] = field(
140+
connection: ConnectionSettings = field(
147141
metadata={'dbus_name': 'connection',
148142
'settings_class': ConnectionSettings},
149-
default=None,
143+
default_factory=ConnectionSettings,
150144
)
151145
dcb: Optional[DcbSettings] = field(
152146
metadata={'dbus_name': 'dcb',

tools/generate-settings-dataclasses-jinja.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ def datatypes_imports(self) -> list[str]:
181181

182182
return datatypes_found
183183

184+
@cached_property
185+
def is_optional_setting(self) -> bool:
186+
if self.name == 'connection':
187+
return False
188+
189+
return True
190+
184191

185192
def extract_docbook_paragraphs(docbook_node: Element) -> List[str]:
186193
return [x.text for x in docbook_node]

tools/jinja_templates/profile.py.jinja2

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,21 @@ class ConnectionProfile:
4747
A group of related key/value pairs describing a specific piece
4848
of a Connection (profile). Keys are also referred to as properties.
4949
"""
50-
# The settings object "connection" is special: It must always be present
51-
# because it contains the UUID and the connection type which are required:
52-
connection: ConnectionSettings = field(
53-
metadata={'dbus_name': 'connection',
54-
'settings_class': ConnectionSettings},
55-
)
56-
# The list of the remaining settings classes was generated by
50+
# The list of the settings classes was generated by
5751
# tools/generate-settings-dataclasses-jinja.py which generates the
5852
# settings classes themselfes as well.
5953
# If possible, please make changes by also updating the script.
6054

6155
# start of the generated list of settings classes
6256
{%- for setting in all_settings %}
63-
{{ setting.snake_name }}: Optional[{{ setting.python_class_name }}] = field(
57+
{{ setting.snake_name }}: {%- if setting.is_optional_setting %} Optional[{{ setting.python_class_name }}] {% else %} {{ setting.python_class_name }} {% endif -%} = field(
6458
metadata={'dbus_name': '{{ setting.name }}',
6559
'settings_class': {{ setting.python_class_name }}},
60+
{%- if setting.is_optional_setting %}
6661
default=None,
62+
{%- else %}
63+
default_factory={{ setting.python_class_name }},
64+
{%- endif %}
6765
)
6866
{%- endfor %}
6967
# end of the generated list of settings classes

0 commit comments

Comments
 (0)