Skip to content

Calling login on a BlueapiClient doesn't allow that client to be used #1567

Description

@tpoliaw

Run blueapi logout to clear any cached tokens.

In a REPL create a new client and login

>>> from blueapi.client import BlueapiClient
>>> bc = BlueapiClient.from_config_file("tests/system_tests/config.yaml")
>>> bc.login()
Logging in
Please login from this URL:- http://localhost:8081/realms/master/device?user_code=ABCD-EFGH
Logged in and cached new token
>>> bc.plans
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/qan22331/.local/share/uv/python/cpython-3.11.15-linux-x86_64-gnu/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/scratch/athena/blueapi/.venv/lib/python3.11/site-packages/observability_utils/tracing/decorators.py", line 151, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/athena/blueapi/src/blueapi/client/client.py", line 260, in plans
    return PlanCache(self, self._rest.get_plans().plans)
                           ^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/athena/blueapi/src/blueapi/client/rest.py", line 202, in get_plans
    return self._request_and_deserialize("/plans", PlanResponse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/athena/blueapi/.venv/lib/python3.11/site-packages/observability_utils/tracing/decorators.py", line 151, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/scratch/athena/blueapi/src/blueapi/client/rest.py", line 324, in _request_and_deserialize
    raise exception
blueapi.client.rest.UnauthorisedAccessError: (401, '{"detail":"Not authenticated"}')

Creating a new client now works as expected so the login did work to some degree

>>> bc = BlueapiClient.from_config_file("tests/system_tests/config.yaml")
>>> bc.plans
PlanCache(8 plans)

Acceptance Criteria

  • bc.login() logs in and lets the client be used

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions