Skip to content
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

Fix: do not require empty data dict for create() #1038

Merged
merged 1 commit into from
Mar 8, 2020
Merged

Fix: do not require empty data dict for create() #1038

merged 1 commit into from
Mar 8, 2020

Conversation

nejch
Copy link
Member

@nejch nejch commented Mar 7, 2020

There's a quirk in the CreateMixin when checking for required attributes in _check_missing_create_attrs, which requires a data dict. But some create methods don't require additional data, e.g. if the only required attribute is already provided by their parent manager id (e.g. for project export, see https://docs.gitlab.com/ee/api/project_import_export.html).

This means the docs are sometimes asking people to pass an empty dict which I think is confusing for newcomers (and maybe unpythonic?).

This small fix allows using create() without passing a dict. The UpdateMixin is doing something similar with new_data = new_data or {} but I thought this is a bit more explicit with None.

I didn't add any checks as the data is already validated in _check_missing_create_attrs based on each Manager's _create_attrs and is already tested (see below), so I hope I covered everything :)

def test_create_mixin_missing_attrs(self):
class M(CreateMixin, FakeManager):
_create_attrs = (("foo",), ("bar", "baz"))
mgr = M(self.gl)
data = {"foo": "bar", "baz": "blah"}
mgr._check_missing_create_attrs(data)
data = {"baz": "blah"}
with self.assertRaises(AttributeError) as error:
mgr._check_missing_create_attrs(data)
self.assertIn("foo", str(error.exception))
.

@max-wittig
Copy link
Member

You're right. This was kinda unpythonic before. Thanks for the change!

@max-wittig max-wittig merged commit ca37d23 into python-gitlab:master Mar 8, 2020
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.

None yet

2 participants