labthings / labthings/labthings-fastapi

Incorrect types in for `Invocation.action`

Open
#403 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
In the OpenFlexure microscope server we use the ActionManager of the server to determine the calling action for an invocation when recording log information. We get the invocation with get_invocation(). Using this Invocation object we can do invocation.action.name to get the action name. But MyPy throws and error unless you call invocation.action().name; this makes MyPy happy but throws an error at runtime. The issues seems to be because the action is a descriptor.

To get around this we directly invocation.action_ref().name which even though there is no leading underscore feels like accessing an internal.

To Reproduce

  • On an Invocation object add the line invocation.action.name
  • Run MyPy

Expected behaviour

MyPy passes as the code is fine

Actual behaviour

MyPy throws and error unless you do invocation.action().name. This errors at runtime.

System:

  • OS: Kuuntu 24.04 (verified also on docker image python:3.11)
  • Python version: 3.11
  • Version: 0.3.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Invocation and ActionManager implementations, especially get_invocation(), action, and action_ref(), then reproduce the issue by checking invocation.action.name with MyPy. Done means the public invocation.action.name usage passes MyPy and works at runtime without requiring the internal-looking action_ref().

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
63/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.