Skip to content

Commit 919440b

Browse files
committed
fix: check attributes.require and .exclusive before using in _validate_attrs (utils.py)
1 parent be018af commit 919440b

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

gitlab/utils.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,20 @@ def _validate_attrs(
171171
if excludes is None:
172172
excludes = []
173173

174-
required = [k for k in attributes.required if k not in excludes]
175-
missing = [attr for attr in required if attr not in data]
176-
177-
if missing:
178-
raise AttributeError(f"Missing attributes: {', '.join(missing)}")
179-
180-
exclusives = [attr for attr in data if attr in attributes.exclusive]
181-
if len(exclusives) > 1:
182-
raise AttributeError(
183-
f"Provide only one of these attributes: {', '.join(exclusives)}"
184-
)
185-
if not exclusives:
186-
raise AttributeError(
187-
f"Must provide one of these attributes: {', '.join(attributes.exclusive)}"
188-
)
174+
if attributes.required:
175+
required = [k for k in attributes.required if k not in excludes]
176+
missing = [attr for attr in required if attr not in data]
177+
if missing:
178+
raise AttributeError(f"Missing attributes: {', '.join(missing)}")
179+
180+
if attributes.exclusive:
181+
exclusives = [attr for attr in data if attr in attributes.exclusive]
182+
if len(exclusives) > 1:
183+
raise AttributeError(
184+
f"Provide only one of these attributes: {', '.join(exclusives)}"
185+
)
186+
if not exclusives:
187+
raise AttributeError(
188+
"Must provide one of these attributes: %(attrs)s"
189+
% {"attrs": ", ".join(attributes.exclusive)}
190+
)

0 commit comments

Comments
 (0)