diff options
author | Walter Rowe <walter.rowe@gmail.com> | 2022-05-31 15:36:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 21:36:14 +0200 |
commit | 3fa330cc341bbedb163ba757c7f6578d735c6efb (patch) | |
tree | 6a27d234a22e77233990ba89991aa41d438c2528 /gitlab/mixins.py | |
parent | 37eb8e0a4f0fd5fc7e221163b84df3461e64475b (diff) | |
download | gitlab-3fa330cc341bbedb163ba757c7f6578d735c6efb.tar.gz |
feat: support mutually exclusive attributes and consolidate validation to fix board lists (#2037)
add exclusive tuple to RequiredOptional data class to support for
mutually exclusive attributes
consolidate _check_missing_create_attrs and _check_missing_update_attrs
from mixins.py into _validate_attrs in utils.py
change _create_attrs in board list manager classes from
required=('label_ld',) to
exclusive=('label_id','asignee_id','milestone_id')
closes https://github.com/python-gitlab/python-gitlab/issues/1897
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r-- | gitlab/mixins.py | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 7e26cea..ec6fa18 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -256,15 +256,6 @@ class CreateMixin(_RestManagerBase): _path: Optional[str] gitlab: gitlab.Gitlab - def _check_missing_create_attrs(self, data: Dict[str, Any]) -> None: - missing = [] - for attr in self._create_attrs.required: - if attr not in data: - missing.append(attr) - continue - if missing: - raise AttributeError(f"Missing attributes: {', '.join(missing)}") - @exc.on_http_error(exc.GitlabCreateError) def create( self, data: Optional[Dict[str, Any]] = None, **kwargs: Any @@ -287,7 +278,7 @@ class CreateMixin(_RestManagerBase): if data is None: data = {} - self._check_missing_create_attrs(data) + utils._validate_attrs(data=data, attributes=self._create_attrs) data, files = utils._transform_types(data, self._types) # Handle specific URL for creation @@ -309,22 +300,6 @@ class UpdateMixin(_RestManagerBase): _update_uses_post: bool = False gitlab: gitlab.Gitlab - def _check_missing_update_attrs(self, data: Dict[str, Any]) -> None: - if TYPE_CHECKING: - assert self._obj_cls is not None - # Remove the id field from the required list as it was previously moved - # to the http path. - required = tuple( - [k for k in self._update_attrs.required if k != self._obj_cls._id_attr] - ) - missing = [] - for attr in required: - if attr not in data: - missing.append(attr) - continue - if missing: - raise AttributeError(f"Missing attributes: {', '.join(missing)}") - def _get_update_method( self, ) -> Callable[..., Union[Dict[str, Any], requests.Response]]: @@ -367,7 +342,12 @@ class UpdateMixin(_RestManagerBase): else: path = f"{self.path}/{utils.EncodedId(id)}" - self._check_missing_update_attrs(new_data) + excludes = [] + if self._obj_cls is not None and self._obj_cls._id_attr is not None: + excludes = [self._obj_cls._id_attr] + utils._validate_attrs( + data=new_data, attributes=self._update_attrs, excludes=excludes + ) new_data, files = utils._transform_types(new_data, self._types) http_method = self._get_update_method() |