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

New REQUIRED level properties #153

Conversation

CasperWA
Copy link
Member

@CasperWA CasperWA commented Feb 3, 2020

Fixes #114
Fixes #154

See commit message.

Note:

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

@CasperWA I have a few minor comments,
but I also need to say that I didn't quite get the main point of the PR, so probably better if we have a quick chat tomorrow (or someone else could review)

optimade/models/entries.py Outdated Show resolved Hide resolved
optimade/models/entries.py Outdated Show resolved Hide resolved
optimade/models/entries.py Outdated Show resolved Hide resolved
@@ -84,7 +84,7 @@ def validate_chemical_symbols(cls, v):
def validate_concentration(cls, v, values):
if len(v) != len(values.get("chemical_symbols", [])):
raise ValueError(
f"Length of concentration ({len(v)}) MUST equal length of chemical_symbols ({len(values.get('chemical_symbols', []))})"
f"Length of concentration ({len(v)}) MUST equal length of chemical_symbols ({len(values.get('chemical_symbols', 'Not specified'))})"
Copy link
Member

Choose a reason for hiding this comment

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

Is 'Not specified' better than None here?

Copy link
Member Author

@CasperWA CasperWA Feb 3, 2020

Choose a reason for hiding this comment

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

I guess it's more informative if you're developing a server, which these messages are mainly for.

Edit: None might be a deliberately set value.

@CasperWA CasperWA changed the title New REQUIRED level properties [WIP] New REQUIRED level properties Feb 3, 2020
@CasperWA CasperWA changed the title [WIP] New REQUIRED level properties New REQUIRED level properties Feb 4, 2020
@CasperWA
Copy link
Member Author

CasperWA commented Feb 4, 2020

I have added a test, repeated 3 times for each endpoint "links", "references" and "structures".
It sets some values for a response_fields request, retrieves all top-level fields, as well as all attributes fields, and then compares to what would be expected according to the new rules, and with what we have in our "database".

@CasperWA CasperWA requested a review from ltalirz February 4, 2020 18:48
@CasperWA
Copy link
Member Author

CasperWA commented Feb 4, 2020

Furthermore, I have opened an issue Materials-Consortia/OPTIMADE#250 to clarify the spec description of REQUIRED, SHOULD, and OPTIONAL fields, with respect to what an implementation should support and what should be in a response (using/not using response_fields).

Copy link
Member

@ml-evs ml-evs left a comment

Choose a reason for hiding this comment

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

Thanks for this @CasperWA, everything here looks sensible. When you're happy with it I can run through this alongside the spec to check that we have all the required fields.

Could you just clarify something for me? It's now possible for implementations to return (by default) a set of fields that would be insufficient to construct our own models from, correct? e.g. if by default an implementation does not return nsites, we cannot build an optimade-python-tools StructureResource as it nsites is required for validating the positions. If this is the case, we might have to think about producing a list somewhere of all our "required" properties so that any future client built from this repo (where the validator itself is an example) can ask for the fields it needs to build our models.

optimade/models/baseinfo.py Show resolved Hide resolved
optimade/models/baseinfo.py Show resolved Hide resolved
@CasperWA CasperWA mentioned this pull request Feb 5, 2020
@CasperWA
Copy link
Member Author

CasperWA commented Feb 5, 2020

Could you just clarify something for me? It's now possible for implementations to return (by default) a set of fields that would be insufficient to construct our own models from, correct? e.g. if by default an implementation does not return nsites, we cannot build an optimade-python-tools StructureResource as it nsites is required for validating the positions. If this is the case, we might have to think about producing a list somewhere of all our "required" properties so that any future client built from this repo (where the validator itself is an example) can ask for the fields it needs to build our models.

Huh, you're right. Didn't think about this, actually. Yeah, we need to take this into account for the validator.

The `handle_response_fields` utility function now assumes that all
fields to be excluded from entries are under `attributes`, since `id`,
`type` and all other top-level non-attributes fields are REQUIRED in the
response, even when not included as a value to `response_fields`.

The mappers can use the class variable `REQUIRED_FIELDS` to have a set
of REQUIRED response fields that MUST be returned, even when not
included as a value to `response_fields`.
Note: At the time of this commit, there are no fields under any
endpoint's attributes that are REQUIRED in the response.
@CasperWA CasperWA force-pushed the fix_114_new_required_level_properties branch from 7fc5adb to 032b7ae Compare February 5, 2020 16:54
@CasperWA CasperWA mentioned this pull request Feb 5, 2020
10 tasks
@CasperWA CasperWA requested a review from ml-evs February 6, 2020 12:09
@ml-evs
Copy link
Member

ml-evs commented Feb 6, 2020

Added my validators and tests. I changed AnyUrl to AnyHttpUrl because you can put any garbage before :// otherwise.

@CasperWA
Copy link
Member Author

CasperWA commented Feb 6, 2020

Could you just clarify something for me? It's now possible for implementations to return (by default) a set of fields that would be insufficient to construct our own models from, correct? e.g. if by default an implementation does not return nsites, we cannot build an optimade-python-tools StructureResource as it nsites is required for validating the positions. If this is the case, we might have to think about producing a list somewhere of all our "required" properties so that any future client built from this repo (where the validator itself is an example) can ask for the fields it needs to build our models.

Huh, you're right. Didn't think about this, actually. Yeah, we need to take this into account for the validator.

Should we get this in for this PR or can it wait? I guess it can be done in a separate PR, although it is related to the same OPTiMaDe PR. This was more about the models, not the validator consequenses ...

@ml-evs
Copy link
Member

ml-evs commented Feb 6, 2020

Should we get this in for this PR or can it wait? I guess it can be done in a separate PR, although it is related to the same OPTiMaDe PR. This was more about the models, not the validator consequenses ...

Another PR, for sure.

@CasperWA CasperWA requested a review from ml-evs February 6, 2020 13:57
@CasperWA CasperWA merged commit 80e2dcc into Materials-Consortia:master Feb 6, 2020
@CasperWA CasperWA deleted the fix_114_new_required_level_properties branch February 6, 2020 13:57
@CasperWA CasperWA mentioned this pull request Feb 6, 2020
CasperWA added a commit that referenced this pull request Feb 6, 2020
Bump to v0.4.0

Changes:

Changes:
- Reorder test files and update testing endpoints setup (#162, @CasperWA)
- Separate the regular and index-meta database server, making sure they're not importing each other (#160, @CasperWA)
- Introduce Starlette/FastAPI HTTP middleware for redirecting URLs ending with a slash to URLs _not_ ending with a slash (#160, @CasperWA)
- Fix validation of `dimension_types` resulting in `response_fields` failing and add tests for `response_fields` (#153, @CasperWA)
- Update entry list property descriptions according to updated OPTiMaDe spec (#153, @CasperWA)
- Validate updated entry list properties and test updated entry list properties (#153, @ml-evs)
- Add OpenAPI schema descriptions for query parameters (#166, @CasperWA)
- Remove custom constrained types `NonnegativeInt` and `conlist` and use instead standard types together with `pydantic`'s `FieldInfo` parameters for schema generation and validation (#166, @shyamd, @CasperWA)
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.

response_fields not working Update models with new levels of REQUIRED response properties
3 participants