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

Pass kwargs to object factory #168

Merged

Conversation

hakkeroid
Copy link
Contributor

The Issue

When you fetch tags from a project and try to access the builds through a tag commit object like in the following snippet:

client = gitlab.Gitlab(..)
project = client.projects.get('some-id')
tag = project.tags.list()[0]
tag.commit.builds()

… then python-gitlab raises an AttributeError in line 1128 in objects.py. This happens because it tries to construct the request url and cannot find self.project_id.

url = '/projects/%s/repository/commits/%s/builds' % (self.project_id, self.id)

What Causes the Issue?

When you fetch tags python-gitlab constructs Tag-objects which call _set_from_dict internally. Then this method checks if it contains data for subobjects and calls subsequently _get_object . At this point the subobjects will be created from the gitlab response data but do not receive any "kwargs" information and as such are missing the project-id.

Possible Solution

I simply passed down the kwargs to _get_object. It solves the specific issue although I am not exactly sure if this is the best way to go. Additionally I am not a huge fan of passing down parameters for too many levels as it feels conceptually wrong.

@hakkeroid
Copy link
Contributor Author

Besides I purposely did not "fix" all locations where _set_from_dict is used. Mainly because I am not sure if you want it to be solved that way. :-)

@gpocentek
Copy link
Contributor

Thank you for taking care of this!

The other _set_from_dict calls update existing objects so they are probably fine as they are.

I made the choice to have something completely dynamic so having several levels of **kwargs is fine with me. Even if it is conceptually wrong ;)

@gpocentek gpocentek merged commit 9da5d69 into python-gitlab:master Oct 23, 2016
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