Materials-Consortia / Materials-Consortia/optimade-python-tools

Preflight client callback to allow queries to be customised per provider

Open
#2,188 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

client suggestions
Dominant language
Python
Stars
91
Forks
54
PR merge metrics
No merged PRs in 30d

Description

cc @mehmetgiritli & @alex-belozerov

It would be nice to have a mechanism to adjust filters before sending them when using custom fields. As an example, when querying a structures endpoint for custom fields e.g. band_gap, we would like to be able to control how that field gets mapped depending on the database being queried. In the simplest case, if someone asks to filter band_gap, then each database-specific prefix can be added so that COD recieves a query for _cod_band_gap, MP receives _mp_band_gap and so on. This avoids the user needing to construct some contorted query for _cod_band_gap > 0 OR _mp_band_gap > 0 for an indeterminate number of prefixes.

This could be straightforwardly implemented by parsing the filter and checking whether fields exist within the standard, then simply prefixing them if not.

In the more general case, it would also be very helpful to perform arbitrary mapping of field names programmatically, which could e.g., map bandgap to _cod_band_gap (note the field name is not the same), and potentially even map input values to reflect differing unit definitions. This could either be via some kind of local mapping or just by allowing general preflight callbacks that can define arbitrary logic (similar to the response callbacks we allow now).

I'm not sure if this is exactly we had in mind in discussions, so please do give your thoughts! This would be a very useful feature, so I'd be happy to help, but if you want it sooner rather than later it might be wise if someone took the lead on developing it.

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 by locating the client path that prepares filter queries for structures endpoints and the existing response-callback mechanism mentioned in the issue. Determine how a preflight callback could map field names and input values per provider before requests are sent. Done should include a decided callback or mapping interface that supports provider-specific custom fields without requiring users to construct provider-prefixed filters.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.