Skip to content

Fix list_properties and search_property in the client - #2461

Open
anikeya9 wants to merge 1 commit into
Materials-Consortia:mainfrom
anikeya9:fix/list-properties-failed-provider
Open

anikeya9 wants to merge 1 commit into
Materials-Consortia:mainfrom
anikeya9:fix/list-properties-failed-provider

Conversation

@anikeya9

Copy link
Copy Markdown
Contributor

Closes #2460

Fixes three bugs in OptimadeClient.list_properties / search_property; see the issue for the reproductions.

Bug Fix Test
A One database that cannot be queried makes list_properties raise AttributeError for all databases (a failed query leaves QueryResults.data as an empty list) Skip databases whose query failed; their error is already reported by get_one. This also removes the # type: ignore that hid the problem from mypy new test_list_properties_failed_database (one of the three test URLs raises a connection error)
B test_list_properties called search_property("structures", "site") with the arguments swapped, so it got {} and its assertion never ran Fix the argument order and the expected list (6 matches on the test server), and assert on the set of databases before looping updated test_list_properties
C search_property returns {} for an entry type that was not listed first, and list_properties discards the entry types listed before Fetch when the requested entry type is missing from the cache, and update the cache instead of replacing it new test_search_property_multiple_entry_types

One extra change, needed for C: property_lists is a mutable class attribute (defaultdict(dict)), and __init__ never set it, so it was only kept per instance because list_properties re-assigned it. Updating it in place would have shared the cache between all OptimadeClient instances, so each client now creates its own in __init__. test_search_property_multiple_entry_types checks this too.

Verification

  • The new tests fail on main (A: AttributeError, C: {} instead of {'https://example.com': ['year']}), in both sync and async mode, and pass with this PR; without the __init__ change, the shared-cache check fails.
  • tests/server/test_client.py passes (144 tests), as do pre-commit and mypy.
  • optimade-get --list-properties structures across all providers: on main it crashed after 5 providers returned errors; with this PR, the same 5 errors are printed and the properties of the other 45 databases are returned.

Design choice: databases whose query failed are left out of the result rather than given an empty list, since an empty list would read as "this database serves no properties". Happy to change this if you prefer otherwise.

🤖 Generated with Claude Code

- `list_properties` no longer raises an AttributeError when one of the
  databases cannot be queried: a failed query leaves its data as an empty
  list, so such databases are now skipped (their error is already
  reported).
- `search_property` now lists the properties of an entry type that has
  not been listed yet, and `list_properties` updates the cache instead of
  replacing it, so earlier entry types are kept.
- Each client now has its own `property_lists` cache rather than sharing
  the mutable class attribute.
- `test_list_properties` called `search_property` with its arguments
  swapped, so its assertion never ran; fix the call and the expected
  value, and add tests for the cases above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (f90d814) to head (7fa1e16).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2461      +/-   ##
==========================================
+ Coverage   90.37%   90.59%   +0.22%     
==========================================
  Files          78       78              
  Lines        5122     5126       +4     
==========================================
+ Hits         4629     4644      +15     
+ Misses        493      482      -11     
Flag Coverage Δ
project 90.59% <100.00%> (+0.22%) ⬆️
validator 90.59% <100.00%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Client: list_properties crashes when a database is unreachable, and search_property bugs

1 participant