Skip to content

Fix AttributeError caused by unknown languages

Tan Le requested to merge fix-lang-id-name-attribute-error into main

What does this merge request do and why?

We are seeing an increased error rate related to 'NoneType' object has no attribute 'name'.

Screenshot_2023-10-04_at_4.20.43_pm

Traceback (most recent call last):
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/anyio/streams/memory.py", line 98, in receive
    return self.receive_nowait()
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/anyio/streams/memory.py", line 93, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/base.py", line 43, in call_next
    message = await recv_stream.receive()
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/anyio/streams/memory.py", line 118, in receive
    raise EndOfStream
anyio.EndOfStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/ai_gateway/api/middleware.py", line 107, in dispatch
    response = await call_next(request)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/base.py", line 46, in call_next
    raise app_exc
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/base.py", line 36, in coro
    await self.app(scope, request.receive, send_stream.send)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 48, in __call__
    await self.app(scope, receive, send)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/base.py", line 68, in __call__
    response = await self.dispatch_func(request, call_next)
  File "/app/ai_gateway/api/middleware.py", line 274, in dispatch
    return await call_next(request)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/base.py", line 46, in call_next
    raise app_exc
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/middleware/base.py", line 36, in coro
    await self.app(scope, request.receive, send_stream.send)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/exceptions.py", line 93, in __call__
    raise exc
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    await self.app(scope, receive, sender)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 670, in __call__
    await route.handle(scope, receive, send)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 266, in handle
    await self.app(scope, receive, send)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/starlette/routing.py", line 65, in app
    response = await func(request)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 231, in app
    raw_response = await run_endpoint_function(
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/fastapi/routing.py", line 160, in run_endpoint_function
    return await dependant.call(**values)
  File "/opt/venv/ai-gateway-9TtSrW0h-py3.9/lib/python3.9/site-packages/dependency_injector/wiring.py", line 994, in _patched
    return await _async_inject(
  File "src/dependency_injector/_cwiring.pyx", line 66, in _async_inject
  File "/app/ai_gateway/api/v2/endpoints/code.py", line 117, in completions
    suggestion = await code_completions(
  File "/app/ai_gateway/code_suggestions/processing/base.py", line 79, in generate
    return await self._generate(
  File "/app/ai_gateway/code_suggestions/processing/completions.py", line 214, in _generate
    watch_container.register_lang(lang_id, editor_lang)
  File "/app/ai_gateway/instrumentators/base.py", line 119, in register_lang
    {"lang": lang_id.name.lower(), "editor_lang": editor_lang}
AttributeError: 'NoneType' object has no attribute 'name'

https://log.gprd.gitlab.net/app/discover#/doc/8cd9c4c0-f0a7-11ed-a017-0d32180b1390/pubsub-mlops-inf-gprd-000022?id=wnn3-IoBouij7zpEyolK

This bug was introduced by !409 (merged)

How to set up and validate locally

  1. Ensure a local Docker image built successfully.
    docker buildx build --platform linux/amd64 \
      -t ai-gateway:test .
  2. Run a local service on Docker.
    docker run --platform linux/amd64 --rm \
      -p 5052:5052 \
      -e AUTH_BYPASS_EXTERNAL=true \
      -v $PWD:/app -it ai-gateway:test
  3. Send a cURL request to the /v2/completions endpoint with an unsupported file extension.
    $ curl --request POST \
      --url http://codesuggestions.gdk.test:5052/v2/completions \
      --header 'Content-Type: application/json' \
      --header 'X-Gitlab-Authentication-Type: oidc' \
      --header 'authorization: Bearer jwt \
      --data '{
      "prompt_version": 1,
      "project_path": "gitlab-org/gitlab",
      "project_id": 278964,
      "current_file": {
        "file_name": "main.vue",
        "content_above_cursor": "# write an awesome function",
        "content_below_cursor": ""
      }
    }'
  4. Observer the error in the log

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Tan Le

Merge request reports