Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow already prefixed fields to be configured as provider fields #1720

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jul 22, 2023

This PR allows provider fields to be put into the config that already contain the prefix. This can eventually be extended to cover definition providers too.

This is useful for the case where a local database has already been prepared with OPTIMADE in mind, and thus database fields already contain the relevant prefix, to avoid adding the prefix twice.

@ml-evs ml-evs added server Issues pertaining to the example server implementation ergonomics Features that improve the usability of the package labels Jul 22, 2023
@codecov
Copy link

codecov bot commented Jul 22, 2023

Codecov Report

Merging #1720 (867cdf3) into master (26b9afa) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1720   +/-   ##
=======================================
  Coverage   90.87%   90.87%           
=======================================
  Files          74       74           
  Lines        4615     4615           
=======================================
  Hits         4194     4194           
  Misses        421      421           
Flag Coverage Δ
project 90.87% <100.00%> (ø)
validator 90.76% <100.00%> (ø)

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

Impacted Files Coverage Δ
...made/server/entry_collections/entry_collections.py 95.83% <ø> (ø)
optimade/server/mappers/entries.py 96.42% <ø> (ø)
optimade/server/schemas.py 94.44% <100.00%> (ø)

@ml-evs ml-evs force-pushed the ml-evs/allow_prefixed_fields branch from 7b1237c to 5cd3d99 Compare July 22, 2023 11:55
@ml-evs ml-evs force-pushed the ml-evs/allow_prefixed_fields branch from 5cd3d99 to 867cdf3 Compare July 22, 2023 13:58
@@ -255,6 +255,8 @@ def all_fields(self) -> Set[str]:
# All provider-specific fields
self._all_fields |= {
f"_{self.provider_prefix}_{field_name}"
if not field_name.startswith("_")
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering could some databases not already have internal field names starting with an underscore, but not a valid prefix ?
In that case, it would be better to check if a whole prefix is present.

Copy link
Member Author

Choose a reason for hiding this comment

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

They could, but unless they define the field in their config then it won't show up anyway. Either way, they should be able to access those fields (they cannot currently) and can configure a mapper to choose a better field name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that is true, I think I used a field name with an underscore to transfer information that was relevant for processing an entry but not useful to share with the users.

@JPBergsma
Copy link
Contributor

I was still wondering, could you perhaps also add a test for queries? So that we can be sure that these fields are also handled correctly in queries.

@ml-evs
Copy link
Member Author

ml-evs commented Jul 25, 2023

I was still wondering, could you perhaps also add a test for queries? So that we can be sure that these fields are also handled correctly in queries.

The validator tests should be taking care of this; every field reported in the info/structures (which is being tested) will have dynamics queries run against it.

Copy link
Contributor

@JPBergsma JPBergsma left a comment

Choose a reason for hiding this comment

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

I assume the response_fields parameter gets tested in the same manner as the queries.
So This PR should be good to go.

@ml-evs ml-evs merged commit 161450d into master Jul 25, 2023
@ml-evs ml-evs deleted the ml-evs/allow_prefixed_fields branch July 25, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ergonomics Features that improve the usability of the package server Issues pertaining to the example server implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants