Skip to content

Aliases now also work for nested fields; Only retrieve data required for constructing a response from the database. - #1304

Open
JPBergsma wants to merge 28 commits into
Materials-Consortia:mainfrom
JPBergsma:JPBergsma/allow_nested_aliases
Open

Aliases now also work for nested fields; Only retrieve data required for constructing a response from the database.#1304
JPBergsma wants to merge 28 commits into
Materials-Consortia:mainfrom
JPBergsma:JPBergsma/allow_nested_aliases

Conversation

@JPBergsma

@JPBergsma JPBergsma commented Aug 17, 2022

Copy link
Copy Markdown
Contributor

I have put some of the changes I made in Barcelona and some more things in this PR.
I got a bit carried away and in hindsight I should probably have split it up in two or more PRs as it has become quite large and involves changes that could have been separated.

I am also still a bit worried that I may have changed too much and that there could be problems with code depending on the optimade python tools.

It now allows mapping to arbitrary nesting levels as long as the fields are separated by ".", which is similar to how they are handled in MongoDB.
Example: "aliases": { "structures": {"OPTIMADE_field": "field.nested_field"} }
It also allows adding database specific fields to top level optimade dictionaries like: "species"
So if you add "species.oxidation_state" to the provider_fields, it will be presented as "species._exmpl_oxidation_state"

The mapping is now done in two steps. One step for removing/adding the prefixes and one step for mapping the optimade field to the backend specific field.

The all_aliases method therefore now only returns the mapping between the optimade fields and the backend fields.
The all_prefixed_fields now contains the pairs of prefixed and unprefixed optimade fields.

Another change that is in this PR is that only the requested fields are now retrieved from the Mongo database. This caused some issues with validation, because fields that are required for a normal response are now no longer present when the response_fields parameter is present. I there for had to make the validation less strict in a few places.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config For issues/PRs related to the server config. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants