Skip to content

Conversation

@rwb27
Copy link
Collaborator

@rwb27 rwb27 commented Nov 18, 2025

This PR adds deprecation warnings for v0.0.12.

Adding the warnings resulted in many, many warnings for the test suite, so I've needed to check and filter out the warnings that are related to test code that will be deleted when dependencies are deleted. This is more or less entirely in tests/old_dependency_tests, with one test in test_docs that will also go once the dependency documentation is removed.

Some of the deprecated dependencies were being used by internal code, which I've modified:

Action Manager

ActionManagerContextDep relied on some of the deprecated functions. However, its function was to supply the ActionManager associated with the current server - and the Thing was already available to the functions that used it. I now retrieve the ActionManager from the ThingServerInterface of the Thing which means no dependency is needed.

I've deleted labthings_fastapi.dependencies.action_manager because it was only used internally and is no longer needed. I've searched the OFM codebase to double-check that it's not used there.

Blob Serialisation

BlobIOContextDep retrieved the BlobManager from the server, which required a dependency.

There's no real reason not to keep a global register of BlobData objects rather than a per-server one: they are indexed by UUID which will be unique globally. I've now made a single, global BlobDataManager object, and eliminated the use of find_server_from_request. This means that the ThingServer no longer holds its own reference to a blob data manager, and it is simply referenced from the module-level global when it's needed.

It would be nice, in due course, to eliminate BlobIOContextDep entirely, but that's for another PR.

Incidental changes

In doing this, I spotted some uncovered lines in outputs.blob and have improved the tests. More work is needed here, noted in #210.

Todo

Before merging, I should:

  • Test ThingServerInterface.action_manager.
  • Mock MockThingServerInterface.action_manager (probably raise a NotImplementedError for now).

Closes #203

@barecheck
Copy link

barecheck bot commented Nov 18, 2025

rwb27 added 11 commits November 20, 2025 09:56
All the functions that have been added to will be removed in v0.0.13.
The `old_dependency_tests` now ignore deprecation warnings for v0.0.13, as those tests will be removed
for that release.

I've also changed the stacklevel on one warning to ensure it is raised on calling code, not in a dependency module.
The filter in pyproject.toml didn't do what I intended, so it's removed. I have used `pytestmark` on all the old dependency test modules instead.
We need to keep using an InvocationID dependency when starting actions, otherwise
all of the Invocation-related dependencies will break.

This commit adds an internal dependency that keeps everything working, but won't raise an error on every action call.

It also removes a spurious CancelHook dependency, that isn't needed.
DirectThingClient will be removed: tests that make use of it will raise warnings.

We've retained enough tests to make sure it stays working for v0.0.12, but tests to make sure other things work properly
for DirectThingClient can be removed now.
I've retained tests for the dependencies, to make sure they don't break before they are removed in v0.0.13.
I've marked the tests to filter out the warnings, but I also needed to manually suppress the DeprecationWarning in the test set-up code.
The only functions that needed `ActionManagerContextDep` already had access to a `Thing` object, so I've added a property to `ThingServerInterface` that allows us to access the action manager that way.

This eliminates deprecation warnings related to the dependency.
The BlobDataManager dependency (which is only ever used internally) used dependencies to obtain the ThingServer, and extracted the BlobDataManager from it.

This is now deprecated: Things can access the server via the ThingServerInterface.

The simplest fix is to make a global BlobDataManager object. This simply allows BlobData objects to be retrieved by UUID. In the future, it may become part of a `BlobData` base class, similar to `CancelEvent`.

This is only a change in behaviour if there is more than one `ThingServer` per Python instance. Even then, the only effect would be that blobs from one server could be accessed from the other server. That's not a supported scenario, and is very unlikely to lead to errors anyway - UUIDs should be unique, so there's no danger of blob IDs colliding.
This is also added to `MockThingServerInterface`. I've not attempted to simulate functionality: accessing the `action manager` on a `MockThingServerInterface` simply raises `NotImplementedError`.
@rwb27 rwb27 force-pushed the deprecation-warnings branch from 98f9608 to 5198d96 Compare November 20, 2025 11:00
This dependency is no longer needed, so I've removed the vestigial code.
When reviewing my PR I spotted many of the test misses were on `blob`, so I've added some more tests here. This module hasn't changed much in the PR, but I have touched it, hence looking at the code.

More improvements here would be nice, and I've opened [#210](#210) to log this.
@rwb27 rwb27 force-pushed the deprecation-warnings branch from 103cc94 to 837b3ec Compare November 20, 2025 12:41
@rwb27 rwb27 requested a review from julianstirling November 20, 2025 12:59
@rwb27 rwb27 added this to the v0.0.12 milestone Nov 20, 2025
Copy link
Contributor

@julianstirling julianstirling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor points, but overall this is fine.

rwb27 and others added 2 commits November 22, 2025 09:38
Co-authored-by: Julian Stirling <julian@julianstirling.co.uk>
This property was only ever intended to be used by LabThings code, so ought to be private.
It is also quite likely to be removed in the future, another good reason for a leading _.
@rwb27
Copy link
Collaborator Author

rwb27 commented Nov 22, 2025

A few minor points, but overall this is fine.

Thanks very much - agreed on the docs and I've noted that in #212. Good shout on ThingServerInterface._action_manager, I've changed that.

@rwb27 rwb27 marked this pull request as ready for review November 22, 2025 09:55
@rwb27 rwb27 merged commit 669bd9d into main Nov 22, 2025
14 checks passed
@rwb27 rwb27 deleted the deprecation-warnings branch November 22, 2025 09:56
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.

Deprecation warnings for v0.0.12

3 participants