Gitlab worker fails because index out of range#1184
Gitlab worker fails because index out of range#1184ryneeverett merged 6 commits intoGothenburgBitFactory:developfrom
Conversation
…e. Handle edge cases for user lookup, including missing, multiple matches, and `also_unassigned`.
|
I fogort the traceback of the error: |
My understanding is that I'm sure there's some room for improvement here but I want to make sure we understand the issue first. |
|
Thanks for your reply. For sure, it only tries to query the user. The problem is generated by [-1]['id'] and the case, that the user does not exist (or is incorrect). As far as I understand that would take the last element of a list, no matter if it's an empty one. |
|
IMO, if the only_if_assigned username does not exist, it ought to throw an error as it currently does rather than log a warning and continue. An improvement would be to catch the IndexErrror in that case and raise an exception with a more helpful error message. I don't think we need to handle
And I think it is implied elsewhere in that doc that the username query should only return an "exact match". |
That’s a good point, but then -1 is also wrong. It implies directly, that the response might contain multiples users. And that’s ok since the Gitlab docs say:
and therefore a response may contain multiple users.
From the bugwarrior docs:
I don’t think so, but may be I rushed over the text. My first thought was: why should this an user and why Bugwarrior do not use my gitlab.login, which was already defined (by the way if you use a Token the user does not matter anymore, the same for GitHub). I understand the use case to query stuff for a different user. May be it would be handy to allow strings and boolean. |
This refers to the
The answer to a lot of "why does bugwarrior do x?" questions is historical. My recollection is that this feature existed before services started aggressively rate banning or disallowing unauthenticated api queries and authentication options were generally optional. And now basic user/password authentication is largely being phased out for api use so the Good point about login not being needed with token authentication. Unfortunately, we're using the login to automatically namespace the 'include_repos' and 'exclude_repos' options and there doesn't seem like a great way to avoid that. It does look like it could be easily deleted from the github service though. |
That wasn't my intention and this is normal and totally ok for grown projects.
I suggest keeping the current logic unchanged in this PR and only improving error handling. As a next step, I would: add proper exception handling with meaningful log output Bests |
👍
What advantage does this have over catching the IndexError?
I don't understand what this means. |
Using IndexError here would technically handle the empty case, but it hides the actual assumption we are making — namely, that the API must return exactly one user.
What I meant is simply documenting in the code that this GitLab endpoint returns a list that either: contains exactly one element, or This would clarify the expected behavior and hopefully avoid further discussions like this in the future. Best regards, |
|
Ok, I updated the code: Handle unresolved usernames gracefully by logging a warning instead of raising an error. Let me know if this addresses your feedback. |
Accept changes by ryneeverett. Co-authored-by: ryneeverett <ryneeverett@gmail.com>
…gnment scenarios
|
Applied your suggested change and updated the tests accordingly. |
… `test_gitlab.py`.
|
I'm guessing CI failed because of the extra newline left at the end of test_gilab.py. Could you remove it or run |
In my case I tried to fetch issues which are assigned to my user and I used
At the moment there aren't any assigned issues and the response contains an empty list. I added some code and updated the tests the for
only_if_assignedbehavior in GitLab service. They handle some additional edge cases for user lookup, including missing, multiple matches, andalso_unassigned.With theses changes I got no error anymore and if I created some issues in the production system, it runs just fine.
If you have any further questions, feel free to contact me.
Bests
Daniel