Skip to content

fix: can't add gitlab personal access token and add more debug log in validate_provider_token #8782

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 11 commits into from
Jun 3, 2025

Conversation

littlebai3618
Copy link
Contributor

@littlebai3618 littlebai3618 commented May 29, 2025

  • This change is worth documenting at https://docs.all-hands.dev/
  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

End-user friendly description of the problem this fixes or functionality this introduces.
When the GitLab server’s /v4/user endpoint returns an empty avatar_url, token validation fails.


Summarize what the PR does, explaining any non-trivial design decisions.

In some self-hosted GitLab instances, the avatar_url field can be returned as None.
When this happens, GitLabService.get_user fails while building a User object, because the User model expects avatar_url to be a string, triggering a pydantic_core._pydantic_core.ValidationError (see stack trace below).

Traceback (most recent call last):
  File "/Users/baii/pycharmProjects/beike/OpenHands/openhands/integrations/utils.py", line 39, in validate_provider_token
    await gitlab_service.get_user()
  File "/Users/baii/pycharmProjects/beike/OpenHands/openhands/integrations/gitlab/gitlab_service.py", line 171, in get_user
    return User(
           ^^^^^
  File "/Users/baii/Library/Caches/pypoetry/virtualenvs/openhands-ai-394k-RCl-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for User
avatar_url
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type

I fixed the issue by adding a check for avatar_url in the method and supplying a default value of empty string

This minimal change resolves the problem in my tests.
I also added two debug log lines to validate_provider_token to make troubleshooting easier.

During the debugging process, I also noticed that the /user/info endpoint and the runtime image build were pulling the user repository using the default gitlab.com instead of the specified GitLab domain. I have fixed both issues.

Please carefully review whether the ProviderToken.host property has a default value when the user does not provide a domain. I'm not very familiar with this repository's code。


Link of any specific issues this addresses:
#8781
#8534

@cunjieliu
Copy link

👍

@enyst enyst requested a review from malhotra5 May 29, 2025 12:10
@malhotra5
Copy link
Contributor

Thanks you for this! I've added one comment but besides that this LGTM

@littlebai3618
Copy link
Contributor Author

Thanks you for this! I've added one comment but besides that this LGTM

I've updated and resubmitted the changes to /runtime/base.py based on your feedback.

@littlebai3618
Copy link
Contributor Author

Fix: Robust Handling of git_provider_tokens in Pipeline

I reviewed the error messages in the pipeline and have fixed the issue.

All errors were caused by the following line:

domain = git_provider_tokens[provider].host if git_provider_tokens[provider].host else provider_domains[provider]

This line failed when git_provider_tokens was None.

I’ve updated the logic to include a more robust fallback mechanism that gracefully handles null or missing values to prevent runtime errors.

@littlebai3618
Copy link
Contributor Author

fix lint error

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
debug statements (python)................................................Passed
pyproject-fmt........................................(no files to check)Skipped
Validate pyproject.toml..............................(no files to check)Skipped
ruff.....................................................................Passed
ruff-format..............................................................Passed
mypy.....................................................................Passed
[main 65a5f5eb] style: apply ruff formatting to utils.py

@malhotra5 malhotra5 enabled auto-merge (squash) June 2, 2025 19:17
@malhotra5 malhotra5 merged commit b706f59 into All-Hands-AI:main Jun 3, 2025
17 checks passed
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.

3 participants