Skip to content

[SYNPY-1870] Rewrite test_caching.py to not use deprecated legacy code#1425

Merged
andrewelamb merged 10 commits into
developfrom
SYNPY-1870
Jul 23, 2026
Merged

[SYNPY-1870] Rewrite test_caching.py to not use deprecated legacy code#1425
andrewelamb merged 10 commits into
developfrom
SYNPY-1870

Conversation

@andrewelamb

@andrewelamb andrewelamb commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Problem:

The integration test tests/integration/synapseclient/core/test_caching.py was written against the legacy pre-OOP API and emitted a large number of DeprecationWarnings (all slated for removal in 5.0.0) on every run. Running the test produced warnings for the legacy Project/File/Entity classes, Synapse.store, Synapse.get, Synapse.getChildren, and — indirectly, through the store path — Synapse.findEntityId, along with the internal legacy machinery those calls fanned out to (_getEntityBundle, _check_entity_restrictions, _getWithEntityBundle_async, Annotations/set_annotations, download_file_entity).

While migrating the test off the deprecated public API, the findEntityId warning turned out to originate in production code, not the test: synapseclient/models/services/search.py::get_id() (used by every model store/get for name+parent resolution) still called the deprecated Synapse.findEntityId via an asyncio executor shim, carrying a # TODO: SYNPY-1623 marker. So the OOP models themselves were still routing through a deprecated method.

Solution:

Migrated the test to the object-oriented models and operations layer, and fixed the underlying production code path so the models no longer depend on a deprecated method.

  • tests/integration/synapseclient/core/test_caching.py:
    • Project/File now come from synapseclient.models instead of the legacy root classes.
    • syn.store(...) / syn.get(...) replaced with the model methods entity.store(synapse_client=syn) / entity.get(synapse_client=syn) (and File(id=id).get(...) for fetch-by-id).
    • syn.getChildren(...) replaced with synapseclient.api.get_children driven through wrap_async_generator_to_sync_generator (the same sync-consumption helper the StorableContainer mixin uses), since the workers run in sync executor threads. This preserves the lightweight "list child IDs" behavior rather than switching to the heavier sync_from_synapse (which would download files and change what the test exercises).
  • synapseclient/models/services/search.py:
    • get_id() now calls find_entity_id_async (per the deprecation guidance, from synapseclient.operations import find_entity_id), replacing the deprecated findEntityId + run_in_executor shim. The async variant is used because get_id is a coroutine; it is imported lazily to avoid an operations → models → search circular import (mirroring how find_entity_id_async itself lazily imports api.get_child).
    • Removed the now-unused import asyncio and the SYNPY-1623 TODO, and updated the docstring reference. Behavior is equivalent: find_entity_id_async resolves the parent via id_of() and calls api.get_child, which supports parentId=None for the Project-by-name lookup — matching the old findEntityId(name, parent) contract.

This resolves the SYNPY-1623 tech debt as a side effect. get_id() has callers across project, folder, file, link, recordset, and table_components; the signature and return contract are unchanged, so all callers are unaffected.

Testing:

  • Ran the affected unit tests before the production change to confirm the failure mode: 7 tests in unit_test_project_async.py / unit_test_folder_async.py failed with pytest_socket.SocketBlockedError because they mocked Synapse.findEntityId, which get_id no longer calls (the real get_child attempted a network call).
  • Updated those tests to mock the new dependency (patch("synapseclient.operations.find_entity_id_async", new_callable=AsyncMock, ...)) and to include synapse_client=self.syn in the corresponding assert_called_once_with assertions.
  • After the fix: 83 passed across the two model test files, and 1185 passed across tests/unit/synapseclient/models/ and tests/unit/synapseclient/operations/.
  • Verified that importing the model store/get path with DeprecationWarning promoted to an error raises nothing, and confirmed no circular import from the lazy find_entity_id_async import.

@andrewelamb
andrewelamb requested a review from a team as a code owner July 15, 2026 15:30
@andrewelamb
andrewelamb marked this pull request as draft July 15, 2026 15:31
@andrewelamb
andrewelamb marked this pull request as ready for review July 15, 2026 15:39

@linglp linglp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Just some minor comments.

Comment thread tests/integration/synapseclient/core/test_caching.py Outdated
Comment thread tests/integration/synapseclient/core/test_caching.py Outdated
Comment thread synapseclient/models/services/search.py Outdated
Comment thread synapseclient/models/services/search.py
@andrewelamb
andrewelamb merged commit 1dc8faa into develop Jul 23, 2026
26 of 32 checks passed
@andrewelamb
andrewelamb deleted the SYNPY-1870 branch July 23, 2026 15:17
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