Skip to content

feat: add support for mutually exclusive attributes, consolidate attribute validation, fix boards.py _create_attr #2037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2022

Conversation

walterrowe
Copy link
Contributor

@walterrowe walterrowe commented May 30, 2022

feat: add support for mutually exclusive attributes, consolidate attribute validation, fix boards.py _create_attr

  • add exclusive tuple to RequiredOptional data class to add 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 #1897

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @walterrowe! Just a few tiny suggestions to get CI passing.

@walterrowe
Copy link
Contributor Author

updates made ..

@walterrowe
Copy link
Contributor Author

updated utils.py _validate_attrs() .. it was unintentionally indented.

@walterrowe
Copy link
Contributor Author

walterrowe commented May 31, 2022

looks like utils.py doesn't know type RequiredOptional used in _validate_attrs param types? does utils.py need "from gitlab import base"?

@walterrowe
Copy link
Contributor Author

added base to imports (from gitlab import types, base)

@walterrowe walterrowe requested a review from nejch May 31, 2022 12:05
@nejch
Copy link
Member

nejch commented May 31, 2022

Thanks for your patience @walterrowe, getting closer now ;)

I suggest you always run a quick tox before pushing, this way the linters will already let you know if something's wrong or if the tests don't pass.

added base to imports (from gitlab import types, base)

Thanks for this. Our linters are quite strict so likely it'll need to be alphabetical, sorry 😁

looks like utils.py doesn't know type RequiredOptional used in _validate_attrs param types? does utils.py need "from gitlab import base"?

You're right, sorry I missed this when I looked at the PR. Because RequiredOptional is in base.py, we also now get a circular import (we import base from utils and vice versa), so it would probably make sense to have RequiredOptional defined in utils.py (but still import it in base e.g. from .utils import RequiredOptional otherwise you'll need to touch a bunch of files). I'll refactor that later if needed.

@walterrowe
Copy link
Contributor Author

looked at the error .. looking for suggestions on how to resolve

@walterrowe
Copy link
Contributor Author

walterrowe commented May 31, 2022

I followed the contributors doc and set up all the pre-commit items. I have addressed them all except these two.

gitlab/utils.py:168: error: Name "RequiredOptional" is not defined
gitlab/mixins.py:345: error: Item "None" of "Optional[Type[RESTObject]]" has no attribute "_id_attr"

utils.py where we declare attributes arg type

def _validate_attrs(
    data: Dict[str, Any],
    attributes: RequiredOptional,
    excludes: Optional[list] = None,
) -> None:

mixins.py where we set excludes

        excludes = [self._obj_cls._id_attr]
        utils._validate_attrs(
            data=new_data, attributes=self._update_attrs, excludes=excludes
        )

@walterrowe
Copy link
Contributor Author

walterrowe commented May 31, 2022

In utils.py ...

from gitlab.base import RequiredOptional

This resolves the RequiredOptional type error and the circular imports between base and utils.

I tried moving RequiredOptional from base to utils and two dozen other files then said they didn't know RequiredOptional so moving it is quite involved. Looking at the groups.py object file I see it tries to import RequiredOptional from base (from gitlab.base import RequiredOptional, RESTManager, RESTObject) so I took the same approach in utils.py.

@nejch - I still get pre-commit complaining about _id_attr in the update method of UpdateMixins in mixins.py:

gitlab/mixins.py:345: error: Item "None" of "Optional[Type[RESTObject]]" has no attribute "_id_attr"

It comes from this line:

        excludes = [self._obj_cls._id_attr]

I moved this ref from the old _check_missing_update_attrs() method.

        required = tuple(
            [k for k in self._update_attrs.required if k != self._obj_cls._id_attr]
        )

I need help with that one. Tracing backwards it appears _id_attr would be inherited from RESTObject, its optional, and defaults to "id". Perhaps in the update method of the UpdateMixin we don't need this, or need to first check if its not None?

@walterrowe
Copy link
Contributor Author

walterrowe commented May 31, 2022

added check for self._obj_cls is not None .. pre-commit runs clean

@walterrowe
Copy link
Contributor Author

@nejch .. now I'm stuck .. any guidance would be helpful.

@JohnVillalovos
Copy link
Member

Just jumping in here without doing a full review. It might make sense to move RequiredOptional to gitlab/types.py.

As gitlab/types.py has no dependencies on any other gitlab module. This should get rid of the circular dependency issue.

@nejch
Copy link
Member

nejch commented May 31, 2022

Thanks @JohnVillalovos that makes sense.

@walterrowe you can move it to types.py and re-import in base.py (and utils.py) for now so that you don't need to touch all the other files.

@JohnVillalovos
Copy link
Member

Thanks @JohnVillalovos that makes sense.

@walterrowe you can move it to types.py and re-import in base.py (and utils.py) for now so that you don't need to touch all the other files.

I created a PR for moving the RequiredOptional as it was not so easy.

#2039

@nejch
Copy link
Member

nejch commented May 31, 2022

@walterrowe the PR above was merged, so if you now rebase your PR on top of our main you should be able to do this pretty easily, just import it from types.py. Thanks! :)

@JohnVillalovos
Copy link
Member

@walterrowe the PR above was merged, so if you now rebase your PR on top of our main you should be able to do this pretty easily, just import it from types.py. Thanks! :)

If you need assistance rebasing please let us know. I may be busy today, but starting tomorrow I will have more free time.

@walterrowe
Copy link
Contributor Author

walterrowe commented May 31, 2022

@walterrowe the PR above was merged, so if you now rebase your PR on top of our main you should be able to do this pretty easily, just import it from types.py. Thanks! :)

If you need assistance rebasing please let us know. I may be busy today, but starting tomorrow I will have more free time.

Sure wish I had seen this before I pushed my commit to update almost all those same files with the same changes. I have the pre-commit setup so it warned me about all of them.

@JohnVillalovos - I might need some assistance at this point since I have pushed my commits to my fork associated with the PR.

@JohnVillalovos
Copy link
Member

@JohnVillalovos - I might need some assistance at this point since I have pushed my commits to my fork associated with the PR.

Give me a few minutes and I will attempt to rebase.

@JohnVillalovos
Copy link
Member

Give me a few minutes and I will attempt to rebase.

@walterrowe I rebased and squashed the PR. I have pushed it to your branch. You will need to re-clone it most likely.

Please let me know if you have questions.

Might be easiest to just do a new:
git clone git@github.com:walterrowe/python-gitlab.git

@walterrowe walterrowe requested a review from JohnVillalovos May 31, 2022 16:39
@walterrowe
Copy link
Contributor Author

who would have thought implementing mutually exclusive attributes would require this much effort! thanks for all the assistance and guidance through this. definitely learning a great deal about python and code review that I didn't know before.

Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting there. Need to figure out the unit test failures.

Thanks!

@walterrowe
Copy link
Contributor Author

fixed the test_mixins_methods refs to _check_missing_create_attrs and _check_missing_update_attrs

Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walterrowe LGTM (Looks Good To Me) 👍

Thanks for all the work on this. I will let @nejch review it too.

And by the way. Nice photography 😊 I'm a complete amateur but enjoying playing with off-camera flash and other stuff on occasion.

Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walterrowe Oh I forgot one thing. Can you "squash" it down to one commit?

I can do it for you if you like.

Basic idea is:

git rebase --interactive HEAD~4

Change the last three lines from pick to squash and edit the commit message.

@codecov-commenter
Copy link

Codecov Report

Merging #2037 (5bf017a) into main (37eb8e0) will decrease coverage by 0.09%.
The diff coverage is 75.86%.

@@            Coverage Diff             @@
##             main    #2037      +/-   ##
==========================================
- Coverage   93.78%   93.68%   -0.10%     
==========================================
  Files          78       78              
  Lines        4984     4985       +1     
==========================================
- Hits         4674     4670       -4     
- Misses        310      315       +5     
Flag Coverage Δ
cli_func_v4 81.80% <68.96%> (+<0.01%) ⬆️
py_func_v4 80.68% <72.41%> (+<0.01%) ⬆️
unit 85.01% <68.96%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/v4/objects/epics.py 75.00% <50.00%> (ø)
gitlab/v4/objects/issues.py 89.15% <50.00%> (ø)
gitlab/utils.py 93.15% <66.66%> (-6.85%) ⬇️
gitlab/mixins.py 92.22% <100.00%> (-0.30%) ⬇️
gitlab/types.py 100.00% <100.00%> (ø)
gitlab/v4/objects/boards.py 90.69% <100.00%> (ø)
gitlab/v4/objects/files.py 100.00% <100.00%> (ø)

@walterrowe
Copy link
Contributor Author

@walterrowe Oh I forgot one thing. Can you "squash" it down to one commit?

I can do it for you if you like.

Basic idea is:

git rebase --interactive HEAD~4

Change the last three lines from pick to squash and edit the commit message.

@JohnVillalovos - I think I successfully did this .. double check?

@JohnVillalovos
Copy link
Member

@JohnVillalovos - I think I successfully did this .. double check?

Squash was successful 👍

Can you do a git commit --amend and edit the commit message?

feat: add support for mutually exclusive attributes, consolidate attribute validation, fix boards.py _create_attr

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

moved RequiredOptional from base.py to types.py  (DELETE THIS) **************************************************

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

DELETE ALL BELOW HERE: **********************************************************************************
fix: check attributes.require and .exclusive before using in _validate_attrs (utils.py)

style: recommended changes in PR review

fix: corrected _check_missing refs to use _validate_attrs refs

…ibute validation, fix boards.py _create_attr

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 #1897
@walterrowe
Copy link
Contributor Author

commit message amended

Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@walterrowe
Copy link
Contributor Author

thanks @JohnVillalovos

is this now pending @nejch review?

@nejch
Copy link
Member

nejch commented May 31, 2022

Thanks for all the work on this @walterrowe! I had some thoughts on the logic for optionals as we said and I'd like to add some tests for this, but I'll do that in a follow-up, let's get this merged :)

@nejch nejch merged commit 3fa330c into python-gitlab:main May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a issue board list by milestone_id still depends on label_id
4 participants