Repository: Materials-Consortia/optimade-python-tools
Pull request #560 (2020-10-19 21:29:37)

Relax models to allow for all SHOULD fields to be None
This PR tracks the relaxation of our models to allow for None values for almost any field. The current approach for this is to make non-should fields have the type pydantic-type `Optional` but a default value of `...`, which is interpreted as a required OpenAPI field that is allowed to be `None`. 

This PR then also adds the OpenAPI `nullable` property to each of these fields, indicating that they can be null.

To-do:

- [x] Change Structure model field types to Optional[...] with default values of `...`
- [x] Update model validators to allow them to be robust to missing data
- [x] Add combinatorial tests for missing data in structures
- [x] Only run server tests under Mongo in CI (rather than all tests)
- [x] Add `nullable` to schema

codecov[bot]: # [Codecov](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=h1) Report
> Merging [#560](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=desc) into [master](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/commit/e7432a2cdbd38f78c7d2dbfacc115d461e4dd9c0?el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560/graphs/tree.svg?width=650&height=150&src=pr&token=UJAtmqkZZO)](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #560      +/-   ##
==========================================
+ Coverage   91.47%   91.51%   +0.03%     
==========================================
  Files          62       62              
  Lines        3110     3110              
==========================================
+ Hits         2845     2846       +1     
+ Misses        265      264       -1     
```

| Flag | Coverage Δ | |
|---|---|---|
| #project | `91.51% <100.00%> (+0.03%)` | :arrow_up: |
| #validator | `63.53% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [optimade/models/structures.py](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560/diff?src=pr&el=tree#diff-b3B0aW1hZGUvbW9kZWxzL3N0cnVjdHVyZXMucHk=) | `95.62% <100.00%> (+0.54%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=footer). Last update [e7432a2...842f65b](https://codecov.io/gh/Materials-Consortia/optimade-python-tools/pull/560?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

ml-evs: Following discussions in the meeting today, it was agreed that we would go down the "required optional" key route for OPTIMADE should fields, so the changes in this PR should (and do) preserve the OpenAPI schema as it is. This has the side effect that some valid OPTIMADE responses will not be able to validated against the OpenAPI schema (which is the case at the moment anyway). This is mostly due to a mismatch between our definitions and OpenAPI, which we can consider tidying in the specification text.

We could consider patching the OpenAPI schema for these SHOULD field models with the OpenAPI property `nullable`, and if we're feeling extra charitable we could try port it upstream to pydantic/FastAPI...
CasperWA: What's the motivation behind only testing the server for the real MongoDB in the CI?
ml-evs: > What's the motivation behind only testing the server for the real MongoDB in the CI?

The server tests are the only bits that use the backend, so testing everything twice is redundant. When I first added the tests in this PR on all of our structures, it was taking 4-5 mins *per backend* to run. You could argue that these tests are overkill anyway (testing all possible combinations of 1-`N` fields being `null` in the response), but I think it's worth doing for at least a few structures. I reduced this to about ~1 minute by only testing a few structures, but it doesn't make sense to me to run e.g. the model tests with Mongo too.
ml-evs: > > What's the motivation behind only testing the server for the real MongoDB in the CI?
> 
> The server tests are the only bits that use the backend, so testing everything twice is redundant. When I first added the tests in this PR on all of our structures, it was taking 4-5 mins _per backend_ to run. You could argue that these tests are overkill anyway (testing all possible combinations of 1-`N` fields being `null` in the response), but I think it's worth doing for at least a few structures. I reduced this to about ~1 minute by only testing a few structures, but it doesn't make sense to me to run e.g. the model tests with Mongo too.

Going to revisit this, I think coverage might actually improve if testing was performed on *only* the awkward edge-case structure, which will speed things up massively. Then we can decide whether we want to keep running all tests with Mongo for extra redudancy
CasperWA: > > What's the motivation behind only testing the server for the real MongoDB in the CI?
> 
> The server tests are the only bits that use the backend, so testing everything twice is redundant. When I first added the tests in this PR on all of our structures, it was taking 4-5 mins _per backend_ to run. You could argue that these tests are overkill anyway (testing all possible combinations of 1-`N` fields being `null` in the response), but I think it's worth doing for at least a few structures. I reduced this to about ~1 minute by only testing a few structures, but it doesn't make sense to me to run e.g. the model tests with Mongo too.

Great. And sounds completely reasonable 👍 
ml-evs: Have added the root validator directly into this PR to see how it interacts with the model changes, but it could also be pulled out. As we're only raising warnings (for now) on `null`, the `if v is None` bits of the field validators should still stay in.

One important think to check is how well `CORRELATED_STRUCTURE_FIELDS` matches with the specification, and if there are any better ways we could include it (instead of a module level constant).
ml-evs: > Let's get this in now and optimize afterwards.
> This is blocking some things in my implementation as well.
> 
> Thanks @ml-evs ! muscle

Could I be slightly awkward and request that we merge #591 (tiny changes but removes a false negative for validation), release a very minor 0.12.4, and _then_ merge this, ready to release 0.13 after the other bigger PRs are finished?

Patch:
diff --git a/.github/workflows/deps_lint.yml b/.github/workflows/deps_lint.yml
index 2f1dacb0..3650a70c 100644
--- a/.github/workflows/deps_lint.yml
+++ b/.github/workflows/deps_lint.yml
@@ -175,8 +175,8 @@ jobs:
         pip install -r requirements.txt
         pip install -r requirements-dev.txt
 
-    - name: Run all tests (using a real MongoDB)
-      run: pytest -rs -vvv --cov=./optimade/ --cov-report=xml tests/
+    - name: Run server tests (using a real MongoDB)
+      run: pytest -rs -vvv --cov=./optimade/ --cov-report=xml tests/server
       env:
         OPTIMADE_CI_FORCE_MONGO: 1
 
diff --git a/openapi/openapi.json b/openapi/openapi.json
index b46e0731..b8bc3301 100644
--- a/openapi/openapi.json
+++ b/openapi/openapi.json
@@ -3020,7 +3020,8 @@
             "title": "Last Modified",
             "type": "string",
             "description": "Date and time representing when the entry was last modified.\n\n- **Type**: timestamp.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - **Response**: REQUIRED in the response unless the query parameter `response_fields` is present and does not include this property.\n\n- **Example**:\n    - As part of JSON response format: `\"2007-04-05T14:30:20Z\"` (i.e., encoded as an [RFC 3339 Internet Date/Time Format](https://tools.ietf.org/html/rfc3339#section-5.6) string.)",
-            "format": "date-time"
+            "format": "date-time",
+            "nullable": true
           },
           "elements": {
             "title": "Elements",
@@ -3028,12 +3029,14 @@
             "items": {
               "type": "string"
             },
-            "description": "Names of the different elements present in the structure.\n\n- **Type**: list of strings.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - The strings are the chemical symbols, i.e., either a single uppercase letter or an uppercase letter followed by a number of lowercase letters.\n    - The order MUST be alphabetical.\n    - Note: This property SHOULD NOT contain the string \"X\" to indicate non-chemical elements or \"vacancy\" to indicate vacancies (in contrast to the field `chemical_symbols` for the `species` property).\n\n- **Examples**:\n    - `[\"Si\"]`\n    - `[\"Al\",\"O\",\"Si\"]`\n\n- **Query examples**:\n    - A filter that matches all records of structures that contain Si, Al **and** O, and possibly other elements: `elements HAS ALL \"Si\", \"Al\", \"O\"`.\n    - To match structures with exactly these three elements, use `elements HAS ALL \"Si\", \"Al\", \"O\" AND elements LENGTH 3`."
+            "description": "Names of the different elements present in the structure.\n\n- **Type**: list of strings.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - The strings are the chemical symbols, i.e., either a single uppercase letter or an uppercase letter followed by a number of lowercase letters.\n    - The order MUST be alphabetical.\n    - Note: This property SHOULD NOT contain the string \"X\" to indicate non-chemical elements or \"vacancy\" to indicate vacancies (in contrast to the field `chemical_symbols` for the `species` property).\n\n- **Examples**:\n    - `[\"Si\"]`\n    - `[\"Al\",\"O\",\"Si\"]`\n\n- **Query examples**:\n    - A filter that matches all records of structures that contain Si, Al **and** O, and possibly other elements: `elements HAS ALL \"Si\", \"Al\", \"O\"`.\n    - To match structures with exactly these three elements, use `elements HAS ALL \"Si\", \"Al\", \"O\" AND elements LENGTH 3`.",
+            "nullable": true
           },
           "nelements": {
             "title": "Nelements",
             "type": "integer",
-            "description": "Number of different elements in the structure as an integer.\n\n- **Type**: integer\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n\n- **Examples**:\n    - `3`\n\n- **Querying**:\n    - Note: queries on this property can equivalently be formulated using `elements LENGTH`.\n    - A filter that matches structures that have exactly 4 elements: `nelements=4`.\n    - A filter that matches structures that have between 2 and 7 elements: `nelements>=2 AND nelements<=7`."
+            "description": "Number of different elements in the structure as an integer.\n\n- **Type**: integer\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n\n- **Examples**:\n    - `3`\n\n- **Querying**:\n    - Note: queries on this property can equivalently be formulated using `elements LENGTH`.\n    - A filter that matches structures that have exactly 4 elements: `nelements=4`.\n    - A filter that matches structures that have between 2 and 7 elements: `nelements>=2 AND nelements<=7`.",
+            "nullable": true
           },
           "elements_ratios": {
             "title": "Elements Ratios",
@@ -3041,18 +3044,21 @@
             "items": {
               "type": "number"
             },
-            "description": "Relative proportions of different elements in the structure.\n\n- **Type**: list of floats\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - Composed by the proportions of elements in the structure as a list of floating point numbers.\n    - The sum of the numbers MUST be 1.0 (within floating point accuracy)\n\n- **Examples**:\n    - `[1.0]`\n    - `[0.3333333333333333, 0.2222222222222222, 0.4444444444444444]`\n\n- **Query examples**:\n    - Note: Useful filters can be formulated using the set operator syntax for correlated values.\n      However, since the values are floating point values, the use of equality comparisons is generally inadvisable.\n    - OPTIONAL: a filter that matches structures where approximately 1/3 of the atoms in the structure are the element Al is: `elements:elements_ratios HAS ALL \"Al\":>0.3333, \"Al\":<0.3334`."
+            "description": "Relative proportions of different elements in the structure.\n\n- **Type**: list of floats\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - Composed by the proportions of elements in the structure as a list of floating point numbers.\n    - The sum of the numbers MUST be 1.0 (within floating point accuracy)\n\n- **Examples**:\n    - `[1.0]`\n    - `[0.3333333333333333, 0.2222222222222222, 0.4444444444444444]`\n\n- **Query examples**:\n    - Note: Useful filters can be formulated using the set operator syntax for correlated values.\n      However, since the values are floating point values, the use of equality comparisons is generally inadvisable.\n    - OPTIONAL: a filter that matches structures where approximately 1/3 of the atoms in the structure are the element Al is: `elements:elements_ratios HAS ALL \"Al\":>0.3333, \"Al\":<0.3334`.",
+            "nullable": true
           },
           "chemical_formula_descriptive": {
             "title": "Chemical Formula Descriptive",
             "type": "string",
-            "description": "The chemical formula for a structure as a string in a form chosen by the API implementation.\n\n- **Type**: string\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - The chemical formula is given as a string consisting of properly capitalized element symbols followed by integers or decimal numbers, balanced parentheses, square, and curly brackets `(`,`)`, `[`,`]`, `{`, `}`, commas, the `+`, `-`, `:` and `=` symbols. The parentheses are allowed to be followed by a number. Spaces are allowed anywhere except within chemical symbols. The order of elements and any groupings indicated by parentheses or brackets are chosen freely by the API implementation.\n    - The string SHOULD be arithmetically consistent with the element ratios in the `chemical_formula_reduced` property.\n    - It is RECOMMENDED, but not mandatory, that symbols, parentheses and brackets, if used, are used with the meanings prescribed by [IUPAC's Nomenclature of Organic Chemistry](https://www.qmul.ac.uk/sbcs/iupac/bibliog/blue.html).\n\n- **Examples**:\n    - `\"(H2O)2 Na\"`\n    - `\"NaCl\"`\n    - `\"CaCO3\"`\n    - `\"CCaO3\"`\n    - `\"(CH3)3N+ - [CH2]2-OH = Me3N+ - CH2 - CH2OH\"`\n\n- **Query examples**:\n    - Note: the free-form nature of this property is likely to make queries on it across different databases inconsistent.\n    - A filter that matches an exactly given formula: `chemical_formula_descriptive=\"(H2O)2 Na\"`.\n    - A filter that does a partial match: `chemical_formula_descriptive CONTAINS \"H2O\"`."
+            "description": "The chemical formula for a structure as a string in a form chosen by the API implementation.\n\n- **Type**: string\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - The chemical formula is given as a string consisting of properly capitalized element symbols followed by integers or decimal numbers, balanced parentheses, square, and curly brackets `(`,`)`, `[`,`]`, `{`, `}`, commas, the `+`, `-`, `:` and `=` symbols. The parentheses are allowed to be followed by a number. Spaces are allowed anywhere except within chemical symbols. The order of elements and any groupings indicated by parentheses or brackets are chosen freely by the API implementation.\n    - The string SHOULD be arithmetically consistent with the element ratios in the `chemical_formula_reduced` property.\n    - It is RECOMMENDED, but not mandatory, that symbols, parentheses and brackets, if used, are used with the meanings prescribed by [IUPAC's Nomenclature of Organic Chemistry](https://www.qmul.ac.uk/sbcs/iupac/bibliog/blue.html).\n\n- **Examples**:\n    - `\"(H2O)2 Na\"`\n    - `\"NaCl\"`\n    - `\"CaCO3\"`\n    - `\"CCaO3\"`\n    - `\"(CH3)3N+ - [CH2]2-OH = Me3N+ - CH2 - CH2OH\"`\n\n- **Query examples**:\n    - Note: the free-form nature of this property is likely to make queries on it across different databases inconsistent.\n    - A filter that matches an exactly given formula: `chemical_formula_descriptive=\"(H2O)2 Na\"`.\n    - A filter that does a partial match: `chemical_formula_descriptive CONTAINS \"H2O\"`.",
+            "nullable": true
           },
           "chemical_formula_reduced": {
             "title": "Chemical Formula Reduced",
             "pattern": "^([A-Z][a-z]?\\d*)*$",
             "type": "string",
-            "description": "The reduced chemical formula for a structure as a string with element symbols and integer chemical proportion numbers.\nThe proportion number MUST be omitted if it is 1.\n\n- **Type**: string\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property.\n      However, support for filters using partial string matching with this property is OPTIONAL (i.e., BEGINS WITH, ENDS WITH, and CONTAINS).\n      Intricate queries on formula components are instead suggested to be formulated using set-type filter operators on the multi valued `elements` and `elements_ratios` properties.\n    - Element names MUST have proper capitalization (e.g., `\"Si\"`, not `\"SI\"` for \"silicon\").\n    - Elements MUST be placed in alphabetical order, followed by their integer chemical proportion number.\n    - For structures with no partial occupation, the chemical proportion numbers are the smallest integers for which the chemical proportion is exactly correct.\n    - For structures with partial occupation, the chemical proportion numbers are integers that within reasonable approximation indicate the correct chemical proportions. The precise details of how to perform the rounding is chosen by the API implementation.\n    - No spaces or separators are allowed.\n\n- **Examples**:\n    - `\"H2NaO\"`\n    - `\"ClNa\"`\n    - `\"CCaO3\"`\n\n- **Query examples**:\n    - A filter that matches an exactly given formula is `chemical_formula_reduced=\"H2NaO\"`."
+            "description": "The reduced chemical formula for a structure as a string with element symbols and integer chemical proportion numbers.\nThe proportion number MUST be omitted if it is 1.\n\n- **Type**: string\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property.\n      However, support for filters using partial string matching with this property is OPTIONAL (i.e., BEGINS WITH, ENDS WITH, and CONTAINS).\n      Intricate queries on formula components are instead suggested to be formulated using set-type filter operators on the multi valued `elements` and `elements_ratios` properties.\n    - Element names MUST have proper capitalization (e.g., `\"Si\"`, not `\"SI\"` for \"silicon\").\n    - Elements MUST be placed in alphabetical order, followed by their integer chemical proportion number.\n    - For structures with no partial occupation, the chemical proportion numbers are the smallest integers for which the chemical proportion is exactly correct.\n    - For structures with partial occupation, the chemical proportion numbers are integers that within reasonable approximation indicate the correct chemical proportions. The precise details of how to perform the rounding is chosen by the API implementation.\n    - No spaces or separators are allowed.\n\n- **Examples**:\n    - `\"H2NaO\"`\n    - `\"ClNa\"`\n    - `\"CCaO3\"`\n\n- **Query examples**:\n    - A filter that matches an exactly given formula is `chemical_formula_reduced=\"H2NaO\"`.",
+            "nullable": true
           },
           "chemical_formula_hill": {
             "title": "Chemical Formula Hill",
@@ -3064,7 +3070,8 @@
             "title": "Chemical Formula Anonymous",
             "pattern": "^([A-Z][a-z]?\\d*)*$",
             "type": "string",
-            "description": "The anonymous formula is the `chemical_formula_reduced`, but where the elements are instead first ordered by their chemical proportion number, and then, in order left to right, replaced by anonymous symbols A, B, C, ..., Z, Aa, Ba, ..., Za, Ab, Bb, ... and so on.\n\n- **Type**: string\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property.\n      However, support for filters using partial string matching with this property is OPTIONAL (i.e., BEGINS WITH, ENDS WITH, and CONTAINS).\n\n- **Examples**:\n    - `\"A2B\"`\n    - `\"A42B42C16D12E10F9G5\"`\n\n- **Querying**:\n    - A filter that matches an exactly given formula is `chemical_formula_anonymous=\"A2B\"`."
+            "description": "The anonymous formula is the `chemical_formula_reduced`, but where the elements are instead first ordered by their chemical proportion number, and then, in order left to right, replaced by anonymous symbols A, B, C, ..., Z, Aa, Ba, ..., Za, Ab, Bb, ... and so on.\n\n- **Type**: string\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property.\n      However, support for filters using partial string matching with this property is OPTIONAL (i.e., BEGINS WITH, ENDS WITH, and CONTAINS).\n\n- **Examples**:\n    - `\"A2B\"`\n    - `\"A42B42C16D12E10F9G5\"`\n\n- **Querying**:\n    - A filter that matches an exactly given formula is `chemical_formula_anonymous=\"A2B\"`.",
+            "nullable": true
           },
           "dimension_types": {
             "title": "Dimension Types",
@@ -3074,12 +3081,14 @@
             "items": {
               "$ref": "#/components/schemas/Periodicity"
             },
-            "description": "List of three integers.\nFor each of the three directions indicated by the three lattice vectors (see property `lattice_vectors`), this list indicates if the direction is periodic (value `1`) or non-periodic (value `0`).\nNote: the elements in this list each refer to the direction of the corresponding entry in `lattice_vectors` and *not* the Cartesian x, y, z directions.\n\n- **Type**: list of integers.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n    - MUST be a list of length 3.\n    - Each integer element MUST assume only the value 0 or 1.\n\n- **Examples**:\n    - For a molecule: `[0, 0, 0]`\n    - For a wire along the direction specified by the third lattice vector: `[0, 0, 1]`\n    - For a 2D surface/slab, periodic on the plane defined by the first and third lattice vectors: `[1, 0, 1]`\n    - For a bulk 3D system: `[1, 1, 1]`"
+            "description": "List of three integers.\nFor each of the three directions indicated by the three lattice vectors (see property `lattice_vectors`), this list indicates if the direction is periodic (value `1`) or non-periodic (value `0`).\nNote: the elements in this list each refer to the direction of the corresponding entry in `lattice_vectors` and *not* the Cartesian x, y, z directions.\n\n- **Type**: list of integers.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n    - MUST be a list of length 3.\n    - Each integer element MUST assume only the value 0 or 1.\n\n- **Examples**:\n    - For a molecule: `[0, 0, 0]`\n    - For a wire along the direction specified by the third lattice vector: `[0, 0, 1]`\n    - For a 2D surface/slab, periodic on the plane defined by the first and third lattice vectors: `[1, 0, 1]`\n    - For a bulk 3D system: `[1, 1, 1]`",
+            "nullable": true
           },
           "nperiodic_dimensions": {
             "title": "Nperiodic Dimensions",
             "type": "integer",
-            "description": "An integer specifying the number of periodic dimensions in the structure, equivalent to the number of non-zero entries in `dimension_types`.\n\n- **Type**: integer\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - The integer value MUST be between 0 and 3 inclusive and MUST be equal to the sum of the items in the `dimension_types` property.\n    - This property only reflects the treatment of the lattice vectors provided for the structure, and not any physical interpretation of the dimensionality of its contents.\n\n- **Examples**:\n    - `2` should be indicated in cases where `dimension_types` is any of `[1, 1, 0]`, `[1, 0, 1]`, `[0, 1, 1]`.\n\n- **Query examples**:\n    - Match only structures with exactly 3 periodic dimensions: `nperiodic_dimensions=3`\n    - Match all structures with 2 or fewer periodic dimensions: `nperiodic_dimensions<=2`"
+            "description": "An integer specifying the number of periodic dimensions in the structure, equivalent to the number of non-zero entries in `dimension_types`.\n\n- **Type**: integer\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n    - The integer value MUST be between 0 and 3 inclusive and MUST be equal to the sum of the items in the `dimension_types` property.\n    - This property only reflects the treatment of the lattice vectors provided for the structure, and not any physical interpretation of the dimensionality of its contents.\n\n- **Examples**:\n    - `2` should be indicated in cases where `dimension_types` is any of `[1, 1, 0]`, `[1, 0, 1]`, `[0, 1, 1]`.\n\n- **Query examples**:\n    - Match only structures with exactly 3 periodic dimensions: `nperiodic_dimensions=3`\n    - Match all structures with 2 or fewer periodic dimensions: `nperiodic_dimensions<=2`",
+            "nullable": true
           },
           "lattice_vectors": {
             "title": "Lattice Vectors",
@@ -3094,7 +3103,8 @@
               "minItems": 3,
               "maxItems": 3
             },
-            "description": "The three lattice vectors in Cartesian coordinates, in \u00e5ngstr\u00f6m (\u00c5).\n\n- **Type**: list of list of floats or unknown values.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n      If supported, filters MAY support only a subset of comparison operators.\n    - MUST be a list of three vectors *a*, *b*, and *c*, where each of the vectors MUST BE a list of the vector's coordinates along the x, y, and z Cartesian coordinates.\n      (Therefore, the first index runs over the three lattice vectors and the second index runs over the x, y, z Cartesian coordinates).\n    - For databases that do not define an absolute Cartesian system (e.g., only defining the length and angles between vectors), the first lattice vector SHOULD be set along *x* and the second on the *xy*-plane.\n    - MUST always contain three vectors of three coordinates each, independently of the elements of property `dimension_types`.\n      The vectors SHOULD by convention be chosen so the determinant of the `lattice_vectors` matrix is different from zero.\n      The vectors in the non-periodic directions have no significance beyond fulfilling these requirements.\n    - The coordinates of the lattice vectors of non-periodic dimensions (i.e., those dimensions for which `dimension_types` is `0`) MAY be given as a list of all `null` values.\n        If a lattice vector contains the value `null`, all coordinates of that lattice vector MUST be `null`.\n\n- **Examples**:\n    - `[[4.0,0.0,0.0],[0.0,4.0,0.0],[0.0,1.0,4.0]]` represents a cell, where the first vector is `(4, 0, 0)`, i.e., a vector aligned along the `x` axis of length 4 \u00c5; the second vector is `(0, 4, 0)`; and the third vector is `(0, 1, 4)`."
+            "description": "The three lattice vectors in Cartesian coordinates, in \u00e5ngstr\u00f6m (\u00c5).\n\n- **Type**: list of list of floats or unknown values.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n      If supported, filters MAY support only a subset of comparison operators.\n    - MUST be a list of three vectors *a*, *b*, and *c*, where each of the vectors MUST BE a list of the vector's coordinates along the x, y, and z Cartesian coordinates.\n      (Therefore, the first index runs over the three lattice vectors and the second index runs over the x, y, z Cartesian coordinates).\n    - For databases that do not define an absolute Cartesian system (e.g., only defining the length and angles between vectors), the first lattice vector SHOULD be set along *x* and the second on the *xy*-plane.\n    - MUST always contain three vectors of three coordinates each, independently of the elements of property `dimension_types`.\n      The vectors SHOULD by convention be chosen so the determinant of the `lattice_vectors` matrix is different from zero.\n      The vectors in the non-periodic directions have no significance beyond fulfilling these requirements.\n    - The coordinates of the lattice vectors of non-periodic dimensions (i.e., those dimensions for which `dimension_types` is `0`) MAY be given as a list of all `null` values.\n        If a lattice vector contains the value `null`, all coordinates of that lattice vector MUST be `null`.\n\n- **Examples**:\n    - `[[4.0,0.0,0.0],[0.0,4.0,0.0],[0.0,1.0,4.0]]` represents a cell, where the first vector is `(4, 0, 0)`, i.e., a vector aligned along the `x` axis of length 4 \u00c5; the second vector is `(0, 4, 0)`; and the third vector is `(0, 1, 4)`.",
+            "nullable": true
           },
           "cartesian_site_positions": {
             "title": "Cartesian Site Positions",
@@ -3107,12 +3117,14 @@
               "minItems": 3,
               "maxItems": 3
             },
-            "description": "Cartesian positions of each site in the structure.\nA site is usually used to describe positions of atoms; what atoms can be encountered at a given site is conveyed by the `species_at_sites` property, and the species themselves are described in the `species` property.\n\n- **Type**: list of list of floats\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n      If supported, filters MAY support only a subset of comparison operators.\n    - It MUST be a list of length equal to the number of sites in the structure, where every element is a list of the three Cartesian coordinates of a site expressed as float values in the unit angstrom (\u00c5).\n    - An entry MAY have multiple sites at the same Cartesian position (for a relevant use of this, see e.g., the property `assemblies`).\n\n- **Examples**:\n    - `[[0,0,0],[0,0,2]]` indicates a structure with two sites, one sitting at the origin and one along the (positive) *z*-axis, 2 \u00c5 away from the origin."
+            "description": "Cartesian positions of each site in the structure.\nA site is usually used to describe positions of atoms; what atoms can be encountered at a given site is conveyed by the `species_at_sites` property, and the species themselves are described in the `species` property.\n\n- **Type**: list of list of floats\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n      If supported, filters MAY support only a subset of comparison operators.\n    - It MUST be a list of length equal to the number of sites in the structure, where every element is a list of the three Cartesian coordinates of a site expressed as float values in the unit angstrom (\u00c5).\n    - An entry MAY have multiple sites at the same Cartesian position (for a relevant use of this, see e.g., the property `assemblies`).\n\n- **Examples**:\n    - `[[0,0,0],[0,0,2]]` indicates a structure with two sites, one sitting at the origin and one along the (positive) *z*-axis, 2 \u00c5 away from the origin.",
+            "nullable": true
           },
           "nsites": {
             "title": "Nsites",
             "type": "integer",
-            "description": "An integer specifying the length of the `cartesian_site_positions` property.\n\n- **Type**: integer\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n\n- **Examples**:\n    - `42`\n\n- **Query examples**:\n    - Match only structures with exactly 4 sites: `nsites=4`\n    - Match structures that have between 2 and 7 sites: `nsites>=2 AND nsites<=7`"
+            "description": "An integer specifying the length of the `cartesian_site_positions` property.\n\n- **Type**: integer\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: MUST be a queryable property with support for all mandatory filter features.\n\n- **Examples**:\n    - `42`\n\n- **Query examples**:\n    - Match only structures with exactly 4 sites: `nsites=4`\n    - Match structures that have between 2 and 7 sites: `nsites>=2 AND nsites<=7`",
+            "nullable": true
           },
           "species": {
             "title": "Species",
@@ -3120,7 +3132,8 @@
             "items": {
               "$ref": "#/components/schemas/Species"
             },
-            "description": "A list describing the species of the sites of this structure.\nSpecies can represent pure chemical elements, virtual-crystal atoms representing a statistical occupation of a given site by multiple chemical elements, and/or a location to which there are attached atoms, i.e., atoms whose precise location are unknown beyond that they are attached to that position (frequently used to indicate hydrogen atoms attached to another element, e.g., a carbon with three attached hydrogens might represent a methyl group, -CH3).\n\n- **Type**: list of dictionary with keys:\n    - `name`: string (REQUIRED)\n    - `chemical_symbols`: list of strings (REQUIRED)\n    - `concentration`: list of float (REQUIRED)\n    - `mass`: float (OPTIONAL)\n    - `original_name`: string (OPTIONAL).\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n        If supported, filters MAY support only a subset of comparison operators.\n    - Each list member MUST be a dictionary with the following keys:\n        - **name**: REQUIRED; gives the name of the species; the **name** value MUST be unique in the `species` list;\n        - **chemical_symbols**: REQUIRED; MUST be a list of strings of all chemical elements composing this species.\n          Each item of the list MUST be one of the following:\n            - a valid chemical-element name, or\n            - the special value `\"X\"` to represent a non-chemical element, or\n            - the special value `\"vacancy\"` to represent that this site has a non-zero probability of having a vacancy (the respective probability is indicated in the `concentration` list, see below).\n\n          If any one entry in the `species` list has a `chemical_symbols` list that is longer than 1 element, the correct flag MUST be set in the list `structure_features`.\n\n        - **concentration**: REQUIRED; MUST be a list of floats, with same length as `chemical_symbols`.\n          The numbers represent the relative concentration of the corresponding chemical symbol in this species.\n          The numbers SHOULD sum to one. Cases in which the numbers do not sum to one typically fall only in the following two categories:\n\n            - Numerical errors when representing float numbers in fixed precision, e.g. for two chemical symbols with concentrations `1/3` and `2/3`, the concentration might look something like `[0.33333333333, 0.66666666666]`. If the client is aware that the sum is not one because of numerical precision, it can renormalize the values so that the sum is exactly one.\n            - Experimental errors in the data present in the database. In this case, it is the responsibility of the client to decide how to process the data.\n\n            Note that concentrations are uncorrelated between different sites (even of the same species).\n\n        - **attached**: OPTIONAL; if provided MUST be a list of length 1 or more of strings of chemical symbols for the elements attached to this site, or \"X\" for a non-chemical element.\n\n        - **nattached**: OPTIONAL; if provided MUST be a list of length 1 or more of integers indicating the number of attached atoms of the kind specified in the value of the `attached` key.\n\n          The implementation MUST include either both or none of the `attached` and `nattached` keys, and if they are provided, they MUST be of the same length.\n          Furthermore, if they are provided, the `structure_features` property MUST include the string `site_attachments`.\n\n        - **mass**: OPTIONAL. If present MUST be a float expressed in a.m.u.\n\n        - **original_name**: OPTIONAL. Can be any valid Unicode string, and SHOULD contain (if specified) the name of the species that is used internally in the source database.\n\n          Note: With regards to \"source database\", we refer to the immediate source being queried via the OPTIMADE API implementation.\n\n          The main use of this field is for source databases that use species names, containing characters that are not allowed (see description of the list property `species_at_sites`).\n\n    - For systems that have only species formed by a single chemical symbol, and that have at most one species per chemical symbol, SHOULD use the chemical symbol as species name (e.g., `\"Ti\"` for titanium, `\"O\"` for oxygen, etc.)\n      However, note that this is OPTIONAL, and client implementations MUST NOT assume that the key corresponds to a chemical symbol, nor assume that if the species name is a valid chemical symbol, that it represents a species with that chemical symbol.\n      This means that a species `{\"name\": \"C\", \"chemical_symbols\": [\"Ti\"], \"concentration\": [1.0]}` is valid and represents a titanium species (and *not* a carbon species).\n    - It is NOT RECOMMENDED that a structure includes species that do not have at least one corresponding site.\n\n- **Examples**:\n    - `[ {\"name\": \"Ti\", \"chemical_symbols\": [\"Ti\"], \"concentration\": [1.0]} ]`: any site with this species is occupied by a Ti atom.\n    - `[ {\"name\": \"Ti\", \"chemical_symbols\": [\"Ti\", \"vacancy\"], \"concentration\": [0.9, 0.1]} ]`: any site with this species is occupied by a Ti atom with 90 % probability, and has a vacancy with 10 % probability.\n    - `[ {\"name\": \"BaCa\", \"chemical_symbols\": [\"vacancy\", \"Ba\", \"Ca\"], \"concentration\": [0.05, 0.45, 0.5], \"mass\": 88.5} ]`: any site with this species is occupied by a Ba atom with 45 % probability, a Ca atom with 50 % probability, and by a vacancy with 5 % probability. The mass of this site is (on average) 88.5 a.m.u.\n    - `[ {\"name\": \"C12\", \"chemical_symbols\": [\"C\"], \"concentration\": [1.0], \"mass\": 12.0} ]`: any site with this species is occupied by a carbon isotope with mass 12.\n    - `[ {\"name\": \"C13\", \"chemical_symbols\": [\"C\"], \"concentration\": [1.0], \"mass\": 13.0} ]`: any site with this species is occupied by a carbon isotope with mass 13.\n    - `[ {\"name\": \"CH3\", \"chemical_symbols\": [\"C\"], \"concentration\": [1.0], \"attached\": [\"H\"], \"nattached\": [3]} ]`: any site with this species is occupied by a methyl group, -CH3, which is represented without specifying precise positions of the hydrogen atoms."
+            "description": "A list describing the species of the sites of this structure.\nSpecies can represent pure chemical elements, virtual-crystal atoms representing a statistical occupation of a given site by multiple chemical elements, and/or a location to which there are attached atoms, i.e., atoms whose precise location are unknown beyond that they are attached to that position (frequently used to indicate hydrogen atoms attached to another element, e.g., a carbon with three attached hydrogens might represent a methyl group, -CH3).\n\n- **Type**: list of dictionary with keys:\n    - `name`: string (REQUIRED)\n    - `chemical_symbols`: list of strings (REQUIRED)\n    - `concentration`: list of float (REQUIRED)\n    - `mass`: float (OPTIONAL)\n    - `original_name`: string (OPTIONAL).\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n        If supported, filters MAY support only a subset of comparison operators.\n    - Each list member MUST be a dictionary with the following keys:\n        - **name**: REQUIRED; gives the name of the species; the **name** value MUST be unique in the `species` list;\n        - **chemical_symbols**: REQUIRED; MUST be a list of strings of all chemical elements composing this species.\n          Each item of the list MUST be one of the following:\n            - a valid chemical-element name, or\n            - the special value `\"X\"` to represent a non-chemical element, or\n            - the special value `\"vacancy\"` to represent that this site has a non-zero probability of having a vacancy (the respective probability is indicated in the `concentration` list, see below).\n\n          If any one entry in the `species` list has a `chemical_symbols` list that is longer than 1 element, the correct flag MUST be set in the list `structure_features`.\n\n        - **concentration**: REQUIRED; MUST be a list of floats, with same length as `chemical_symbols`.\n          The numbers represent the relative concentration of the corresponding chemical symbol in this species.\n          The numbers SHOULD sum to one. Cases in which the numbers do not sum to one typically fall only in the following two categories:\n\n            - Numerical errors when representing float numbers in fixed precision, e.g. for two chemical symbols with concentrations `1/3` and `2/3`, the concentration might look something like `[0.33333333333, 0.66666666666]`. If the client is aware that the sum is not one because of numerical precision, it can renormalize the values so that the sum is exactly one.\n            - Experimental errors in the data present in the database. In this case, it is the responsibility of the client to decide how to process the data.\n\n            Note that concentrations are uncorrelated between different sites (even of the same species).\n\n        - **attached**: OPTIONAL; if provided MUST be a list of length 1 or more of strings of chemical symbols for the elements attached to this site, or \"X\" for a non-chemical element.\n\n        - **nattached**: OPTIONAL; if provided MUST be a list of length 1 or more of integers indicating the number of attached atoms of the kind specified in the value of the `attached` key.\n\n          The implementation MUST include either both or none of the `attached` and `nattached` keys, and if they are provided, they MUST be of the same length.\n          Furthermore, if they are provided, the `structure_features` property MUST include the string `site_attachments`.\n\n        - **mass**: OPTIONAL. If present MUST be a float expressed in a.m.u.\n\n        - **original_name**: OPTIONAL. Can be any valid Unicode string, and SHOULD contain (if specified) the name of the species that is used internally in the source database.\n\n          Note: With regards to \"source database\", we refer to the immediate source being queried via the OPTIMADE API implementation.\n\n          The main use of this field is for source databases that use species names, containing characters that are not allowed (see description of the list property `species_at_sites`).\n\n    - For systems that have only species formed by a single chemical symbol, and that have at most one species per chemical symbol, SHOULD use the chemical symbol as species name (e.g., `\"Ti\"` for titanium, `\"O\"` for oxygen, etc.)\n      However, note that this is OPTIONAL, and client implementations MUST NOT assume that the key corresponds to a chemical symbol, nor assume that if the species name is a valid chemical symbol, that it represents a species with that chemical symbol.\n      This means that a species `{\"name\": \"C\", \"chemical_symbols\": [\"Ti\"], \"concentration\": [1.0]}` is valid and represents a titanium species (and *not* a carbon species).\n    - It is NOT RECOMMENDED that a structure includes species that do not have at least one corresponding site.\n\n- **Examples**:\n    - `[ {\"name\": \"Ti\", \"chemical_symbols\": [\"Ti\"], \"concentration\": [1.0]} ]`: any site with this species is occupied by a Ti atom.\n    - `[ {\"name\": \"Ti\", \"chemical_symbols\": [\"Ti\", \"vacancy\"], \"concentration\": [0.9, 0.1]} ]`: any site with this species is occupied by a Ti atom with 90 % probability, and has a vacancy with 10 % probability.\n    - `[ {\"name\": \"BaCa\", \"chemical_symbols\": [\"vacancy\", \"Ba\", \"Ca\"], \"concentration\": [0.05, 0.45, 0.5], \"mass\": 88.5} ]`: any site with this species is occupied by a Ba atom with 45 % probability, a Ca atom with 50 % probability, and by a vacancy with 5 % probability. The mass of this site is (on average) 88.5 a.m.u.\n    - `[ {\"name\": \"C12\", \"chemical_symbols\": [\"C\"], \"concentration\": [1.0], \"mass\": 12.0} ]`: any site with this species is occupied by a carbon isotope with mass 12.\n    - `[ {\"name\": \"C13\", \"chemical_symbols\": [\"C\"], \"concentration\": [1.0], \"mass\": 13.0} ]`: any site with this species is occupied by a carbon isotope with mass 13.\n    - `[ {\"name\": \"CH3\", \"chemical_symbols\": [\"C\"], \"concentration\": [1.0], \"attached\": [\"H\"], \"nattached\": [3]} ]`: any site with this species is occupied by a methyl group, -CH3, which is represented without specifying precise positions of the hydrogen atoms.",
+            "nullable": true
           },
           "species_at_sites": {
             "title": "Species At Sites",
@@ -3128,7 +3141,8 @@
             "items": {
               "type": "string"
             },
-            "description": "Name of the species at each site (where values for sites are specified with the same order of the property `cartesian_site_positions`).\nThe properties of the species are found in the property `species`.\n\n- **Type**: list of strings.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n      If supported, filters MAY support only a subset of comparison operators.\n    - MUST have length equal to the number of sites in the structure (first dimension of the list property `cartesian_site_positions`).\n    - Each species name mentioned in the `species_at_sites` list MUST be described in the list property `species` (i.e. for each value in the `species_at_sites` list there MUST exist exactly one dictionary in the `species` list with the `name` attribute equal to the corresponding `species_at_sites` value).\n    - Each site MUST be associated only to a single species.\n      **Note**: However, species can represent mixtures of atoms, and multiple species MAY be defined for the same chemical element.\n      This latter case is useful when different atoms of the same type need to be grouped or distinguished, for instance in simulation codes to assign different initial spin states.\n\n- **Examples**:\n    - `[\"Ti\",\"O2\"]` indicates that the first site is hosting a species labeled `\"Ti\"` and the second a species labeled `\"O2\"`.\n    - `[\"Ac\", \"Ac\", \"Ag\", \"Ir\"]` indicating the first two sites contains the `\"Ac\"` species, while the third and fourth sites contain the `\"Ag\"` and `\"Ir\"` species, respectively."
+            "description": "Name of the species at each site (where values for sites are specified with the same order of the property `cartesian_site_positions`).\nThe properties of the species are found in the property `species`.\n\n- **Type**: list of strings.\n\n- **Requirements/Conventions**:\n    - **Support**: SHOULD be supported by all implementations, i.e., SHOULD NOT be `null`.\n    - **Query**: Support for queries on this property is OPTIONAL.\n      If supported, filters MAY support only a subset of comparison operators.\n    - MUST have length equal to the number of sites in the structure (first dimension of the list property `cartesian_site_positions`).\n    - Each species name mentioned in the `species_at_sites` list MUST be described in the list property `species` (i.e. for each value in the `species_at_sites` list there MUST exist exactly one dictionary in the `species` list with the `name` attribute equal to the corresponding `species_at_sites` value).\n    - Each site MUST be associated only to a single species.\n      **Note**: However, species can represent mixtures of atoms, and multiple species MAY be defined for the same chemical element.\n      This latter case is useful when different atoms of the same type need to be grouped or distinguished, for instance in simulation codes to assign different initial spin states.\n\n- **Examples**:\n    - `[\"Ti\",\"O2\"]` indicates that the first site is hosting a species labeled `\"Ti\"` and the second a species labeled `\"O2\"`.\n    - `[\"Ac\", \"Ac\", \"Ag\", \"Ir\"]` indicating the first two sites contains the `\"Ac\"` species, while the third and fourth sites contain the `\"Ag\"` and `\"Ir\"` species, respectively.",
+            "nullable": true
           },
           "assemblies": {
             "title": "Assemblies",
diff --git a/optimade/models/entries.py b/optimade/models/entries.py
index 9a74189a..f26cc7a8 100644
--- a/optimade/models/entries.py
+++ b/optimade/models/entries.py
@@ -74,7 +74,7 @@ class EntryResourceAttributes(Attributes):
         queryable=SupportLevel.MUST,
     )
 
-    last_modified: datetime = OptimadeField(
+    last_modified: Optional[datetime] = OptimadeField(
         ...,
         description="""Date and time representing when the entry was last modified.
 
diff --git a/optimade/models/structures.py b/optimade/models/structures.py
index 82ad7f1c..dc2bebb8 100644
--- a/optimade/models/structures.py
+++ b/optimade/models/structures.py
@@ -1,5 +1,6 @@
 # pylint: disable=no-self-argument,line-too-long,no-name-in-module
 import re
+import warnings
 from enum import IntEnum, Enum
 from sys import float_info
 from typing import List, Optional, Union
@@ -16,6 +17,7 @@ from optimade.models.utils import (
     ANONYMOUS_ELEMENTS,
     CHEMICAL_FORMULA_REGEXP,
 )
+from optimade.server.warnings import MissingExpectedField
 
 EXTENDED_CHEMICAL_SYMBOLS = CHEMICAL_SYMBOLS + EXTRA_SYMBOLS
 
@@ -143,7 +145,7 @@ Note: With regards to "source database", we refer to the immediate source being
 
     @validator("concentration")
     def validate_concentration(cls, v, values):
-        if "chemical_symbols" in values:
+        if values.get("chemical_symbols"):
             if len(v) != len(values["chemical_symbols"]):
                 raise ValueError(
                     f"Length of concentration ({len(v)}) MUST equal length of chemical_symbols "
@@ -242,10 +244,18 @@ The possible reasons for the values not to sum to one are the same as already sp
         return v
 
 
+CORRELATED_STRUCTURE_FIELDS = (
+    {"dimension_types", "nperiodic_dimensions"},
+    {"cartesian_site_positions", "species_at_sites"},
+    {"nsites", "cartesian_site_positions"},
+    {"species_at_sites", "species"},
+)
+
+
 class StructureResourceAttributes(EntryResourceAttributes):
     """This class contains the Field for the attributes used to represent a structure, e.g. unit cell, atoms, positions."""
 
-    elements: List[str] = OptimadeField(
+    elements: Optional[List[str]] = OptimadeField(
         ...,
         description="""Names of the different elements present in the structure.
 
@@ -269,7 +279,7 @@ class StructureResourceAttributes(EntryResourceAttributes):
         queryable=SupportLevel.MUST,
     )
 
-    nelements: int = OptimadeField(
+    nelements: Optional[int] = OptimadeField(
         ...,
         description="""Number of different elements in the structure as an integer.
 
@@ -290,7 +300,7 @@ class StructureResourceAttributes(EntryResourceAttributes):
         queryable=SupportLevel.MUST,
     )
 
-    elements_ratios: List[float] = OptimadeField(
+    elements_ratios: Optional[List[float]] = OptimadeField(
         ...,
         description="""Relative proportions of different elements in the structure.
 
@@ -314,7 +324,7 @@ class StructureResourceAttributes(EntryResourceAttributes):
         queryable=SupportLevel.MUST,
     )
 
-    chemical_formula_descriptive: str = OptimadeField(
+    chemical_formula_descriptive: Optional[str] = OptimadeField(
         ...,
         description="""The chemical formula for a structure as a string in a form chosen by the API implementation.
 
@@ -342,7 +352,7 @@ class StructureResourceAttributes(EntryResourceAttributes):
         queryable=SupportLevel.MUST,
     )
 
-    chemical_formula_reduced: str = OptimadeField(
+    chemical_formula_reduced: Optional[str] = OptimadeField(
         ...,
         description="""The reduced chemical formula for a structure as a string with element symbols and integer chemical proportion numbers.
 The proportion number MUST be omitted if it is 1.
@@ -403,7 +413,7 @@ The proportion number MUST be omitted if it is 1.
         regex=CHEMICAL_FORMULA_REGEXP,
     )
 
-    chemical_formula_anonymous: str = OptimadeField(
+    chemical_formula_anonymous: Optional[str] = OptimadeField(
         ...,
         description="""The anonymous formula is the `chemical_formula_reduced`, but where the elements are instead first ordered by their chemical proportion number, and then, in order left to right, replaced by anonymous symbols A, B, C, ..., Z, Aa, Ba, ..., Za, Ab, Bb, ... and so on.
 
@@ -425,8 +435,10 @@ The proportion number MUST be omitted if it is 1.
         regex=CHEMICAL_FORMULA_REGEXP,
     )
 
-    dimension_types: conlist(Periodicity, min_items=3, max_items=3) = OptimadeField(
-        ...,
+    dimension_types: Optional[
+        conlist(Periodicity, min_items=3, max_items=3)
+    ] = OptimadeField(
+        None,
         description="""List of three integers.
 For each of the three directions indicated by the three lattice vectors (see property `lattice_vectors`), this list indicates if the direction is periodic (value `1`) or non-periodic (value `0`).
 Note: the elements in this list each refer to the direction of the corresponding entry in `lattice_vectors` and *not* the Cartesian x, y, z directions.
@@ -448,7 +460,7 @@ Note: the elements in this list each refer to the direction of the corresponding
         queryable=SupportLevel.OPTIONAL,
     )
 
-    nperiodic_dimensions: int = OptimadeField(
+    nperiodic_dimensions: Optional[int] = OptimadeField(
         ...,
         description="""An integer specifying the number of periodic dimensions in the structure, equivalent to the number of non-zero entries in `dimension_types`.
 
@@ -470,10 +482,10 @@ Note: the elements in this list each refer to the direction of the corresponding
         queryable=SupportLevel.MUST,
     )
 
-    lattice_vectors: conlist(
-        Vector3D_unknown, min_items=3, max_items=3
-    ) = OptimadeField(
-        ...,
+    lattice_vectors: Optional[
+        conlist(Vector3D_unknown, min_items=3, max_items=3)
+    ] = OptimadeField(
+        None,
         description="""The three lattice vectors in Cartesian coordinates, in ångström (Å).
 
 - **Type**: list of list of floats or unknown values.
@@ -498,7 +510,7 @@ Note: the elements in this list each refer to the direction of the corresponding
         queryable=SupportLevel.OPTIONAL,
     )
 
-    cartesian_site_positions: List[Vector3D] = OptimadeField(
+    cartesian_site_positions: Optional[List[Vector3D]] = OptimadeField(
         ...,
         description="""Cartesian positions of each site in the structure.
 A site is usually used to describe positions of atoms; what atoms can be encountered at a given site is conveyed by the `species_at_sites` property, and the species themselves are described in the `species` property.
@@ -519,7 +531,7 @@ A site is usually used to describe positions of atoms; what atoms can be encount
         queryable=SupportLevel.OPTIONAL,
     )
 
-    nsites: int = OptimadeField(
+    nsites: Optional[int] = OptimadeField(
         ...,
         description="""An integer specifying the length of the `cartesian_site_positions` property.
 
@@ -539,7 +551,7 @@ A site is usually used to describe positions of atoms; what atoms can be encount
         support=SupportLevel.SHOULD,
     )
 
-    species: List[Species] = OptimadeField(
+    species: Optional[List[Species]] = OptimadeField(
         ...,
         description="""A list describing the species of the sites of this structure.
 Species can represent pure chemical elements, virtual-crystal atoms representing a statistical occupation of a given site by multiple chemical elements, and/or a location to which there are attached atoms, i.e., atoms whose precise location are unknown beyond that they are attached to that position (frequently used to indicate hydrogen atoms attached to another element, e.g., a carbon with three attached hydrogens might represent a methyl group, -CH3).
@@ -605,7 +617,7 @@ Species can represent pure chemical elements, virtual-crystal atoms representing
         queryable=SupportLevel.OPTIONAL,
     )
 
-    species_at_sites: List[str] = OptimadeField(
+    species_at_sites: Optional[List[str]] = OptimadeField(
         ...,
         description="""Name of the species at each site (where values for sites are specified with the same order of the property `cartesian_site_positions`).
 The properties of the species are found in the property `species`.
@@ -764,6 +776,48 @@ The properties of the species are found in the property `species`.
         queryable=SupportLevel.MUST,
     )
 
+    class Config:
+        def schema_extra(schema, model):
+            """Two things need to be added to the schema:
+
+            1. Constrained types in pydantic do not currently play nicely with
+            "Required Optional" fields, i.e. fields must be specified but can be null.
+            The two contrained list fields, `dimension_types` and `lattice_vectors`,
+            are OPTIMADE 'SHOULD' fields, which means that they are allowed to be null.
+
+            2. All OPTIMADE 'SHOULD' fields are allowed to be null, so we manually set them
+            to be `nullable` according to the OpenAPI definition.
+
+            """
+            schema["required"].insert(7, "dimension_types")
+            schema["required"].insert(9, "lattice_vectors")
+
+            nullable_props = (
+                prop
+                for prop in schema["required"]
+                if schema["properties"][prop].get("support") == SupportLevel.SHOULD
+            )
+            for prop in nullable_props:
+                schema["properties"][prop]["nullable"] = True
+
+    @root_validator(pre=True)
+    def warn_on_missing_correlated_fields(cls, values):
+        """Emit warnings if a field takes a null value when a value
+        was expected based on the value/nullity of another field.
+        """
+        accumulated_warnings = []
+        for field_set in CORRELATED_STRUCTURE_FIELDS:
+            missing_fields = {f for f in field_set if values.get(f) is None}
+            if missing_fields and len(missing_fields) != len(field_set):
+                accumulated_warnings += [
+                    f"Structure with values {values} is missing fields {missing_fields} which are required if {field_set - missing_fields} are present."
+                ]
+
+        for warn in accumulated_warnings:
+            warnings.warn(warn, MissingExpectedField)
+
+        return values
+
     @validator("chemical_formula_reduced", "chemical_formula_hill")
     def check_ordered_formula(cls, v, field):
         if v is None:
@@ -800,6 +854,9 @@ The properties of the species are found in the property `species`.
 
     @validator("chemical_formula_anonymous")
     def check_anonymous_formula(cls, v):
+        if v is None:
+            return v
+
         elements = tuple(re.findall(r"[A-Z][a-z]*", v))
         numbers = [int(n.strip()) for n in re.split(r"[A-Z][a-z]*", v) if n.strip()]
 
@@ -830,12 +887,18 @@ The properties of the species are found in the property `species`.
 
     @validator("elements")
     def elements_must_be_alphabetical(cls, v):
+        if v is None:
+            return v
+
         if sorted(v) != v:
             raise ValueError(f"elements must be sorted alphabetically, but is: {v}")
         return v
 
     @validator("elements_ratios")
     def ratios_must_sum_to_one(cls, v):
+        if v is None:
+            return v
+
         if abs(sum(v) - 1) > EPS:
             raise ValueError(
                 f"elements_ratios MUST sum to 1 within floating point accuracy. It sums to: {sum(v)}"
@@ -844,12 +907,10 @@ The properties of the species are found in the property `species`.
 
     @validator("nperiodic_dimensions")
     def check_periodic_dimensions(cls, v, values):
-        if values.get("dimension_types", []) and v is None:
-            raise ValueError(
-                "nperiodic_dimensions is REQUIRED, since dimension_types was provided."
-            )
+        if v is None:
+            return v
 
-        if v != sum(values.get("dimension_types")):
+        if values.get("dimension_types") and v != sum(values.get("dimension_types")):
             raise ValueError(
                 f"nperiodic_dimensions ({v}) does not match expected value of {sum(values['dimension_types'])} "
                 f"from dimension_types ({values['dimension_types']})"
@@ -859,26 +920,24 @@ The properties of the species are found in the property `species`.
 
     @validator("lattice_vectors", always=True)
     def required_if_dimension_types_has_one(cls, v, values):
-        if (
-            Periodicity.PERIODIC.value in values.get("dimension_types", [])
-            and v is None
-        ):
-            raise ValueError(
-                f"lattice_vectors is REQUIRED, since dimension_types is not ({(Periodicity.APERIODIC.value,) * 3}) but is "
-                f"{tuple(getattr(_, 'value', None) for _ in values.get('dimension_types', []))}"
-            )
+        if v is None:
+            return v
 
-        for dim_type, vector in zip(values.get("dimension_types", (None,) * 3), v):
-            if None in vector and dim_type == Periodicity.PERIODIC.value:
-                raise ValueError(
-                    f"Null entries in lattice vectors are only permitted when the corresponding dimension type is {Periodicity.APERIODIC.value}. "
-                    f"Here: dimension_types = {tuple(getattr(_, 'value', None) for _ in values.get('dimension_types', []))}, lattice_vectors = {v}"
-                )
+        if values.get("dimension_types"):
+            for dim_type, vector in zip(values.get("dimension_types", (None,) * 3), v):
+                if None in vector and dim_type == Periodicity.PERIODIC.value:
+                    raise ValueError(
+                        f"Null entries in lattice vectors are only permitted when the corresponding dimension type is {Periodicity.APERIODIC.value}. "
+                        f"Here: dimension_types = {tuple(getattr(_, 'value', None) for _ in values.get('dimension_types', []))}, lattice_vectors = {v}"
+                    )
 
         return v
 
     @validator("lattice_vectors")
     def null_values_for_whole_vector(cls, v):
+        if v is None:
+            return v
+
         for vector in v:
             if None in vector and any((isinstance(_, float) for _ in vector)):
                 raise ValueError(
@@ -888,7 +947,12 @@ The properties of the species are found in the property `species`.
 
     @validator("nsites")
     def validate_nsites(cls, v, values):
-        if v != len(values.get("cartesian_site_positions", [])):
+        if v is None:
+            return v
+
+        if values.get("cartesian_site_positions") and v != len(
+            values.get("cartesian_site_positions", [])
+        ):
             raise ValueError(
                 f"nsites (value: {v}) MUST equal length of cartesian_site_positions "
                 f"(value: {len(values.get('cartesian_site_positions', []))})"
@@ -897,35 +961,39 @@ The properties of the species are found in the property `species`.
 
     @validator("species_at_sites")
     def validate_species_at_sites(cls, v, values):
-        if "nsites" not in values:
-            raise ValueError(
-                "Attribute nsites missing so unable to verify species_at_sites."
-            )
-        if len(v) != values.get("nsites", 0):
+        if v is None:
+            return v
+
+        if values.get("nsites") and len(v) != values.get("nsites"):
             raise ValueError(
                 f"Number of species_at_sites (value: {len(v)}) MUST equal number of sites "
                 f"(value: {values.get('nsites', 'Not specified')})"
             )
-        all_species_names = {
-            getattr(_, "name", None) for _ in values.get("species", [{}])
-        }
-        all_species_names -= {None}
-        for value in v:
-            if value not in all_species_names:
-                raise ValueError(
-                    "species_at_sites MUST be represented by a species' name, "
-                    f"but {value} was not found in the list of species names: {all_species_names}"
-                )
+        if values.get("species"):
+            all_species_names = {
+                getattr(_, "name", None) for _ in values.get("species", [{}])
+            }
+            all_species_names -= {None}
+            for value in v:
+                if value not in all_species_names:
+                    raise ValueError(
+                        "species_at_sites MUST be represented by a species' name, "
+                        f"but {value} was not found in the list of species names: {all_species_names}"
+                    )
         return v
 
     @validator("species")
     def validate_species(cls, v):
+        if v is None:
+            return v
+
         all_species = [_.name for _ in v]
         unique_species = set(all_species)
         if len(all_species) != len(unique_species):
             raise ValueError(
                 f"Species MUST be unique based on their 'name'. Found species names: {all_species}"
             )
+
         return v
 
     @validator("structure_features", always=True)
@@ -934,66 +1002,71 @@ The properties of the species are found in the property `species`.
             raise ValueError(
                 f"structure_features MUST be sorted alphabetically, given value: {v}"
             )
-        # disorder
-        for species in values.get("species", []):
-            if len(species.chemical_symbols) > 1:
-                if StructureFeatures.DISORDER not in v:
-                    raise ValueError(
-                        f"{StructureFeatures.DISORDER.value} MUST be present when any one entry in species "
-                        "has a chemical_symbols list greater than one element"
-                    )
-                break
-        else:
-            if StructureFeatures.DISORDER in v:
-                raise ValueError(
-                    f"{StructureFeatures.DISORDER.value} MUST NOT be present, since all species' chemical_symbols "
-                    "lists are equal to or less than one element"
-                )
+
         # assemblies
-        if values.get("assemblies", None) is not None:
+        if values.get("assemblies") is not None:
             if StructureFeatures.ASSEMBLIES not in v:
                 raise ValueError(
                     f"{StructureFeatures.ASSEMBLIES.value} MUST be present, since the property of the same name is present"
                 )
-        else:
-            if StructureFeatures.ASSEMBLIES in v:
-                raise ValueError(
-                    f"{StructureFeatures.ASSEMBLIES.value} MUST NOT be present, "
-                    "since the property of the same name is not present"
-                )
-        # site_attachments
-        for species in values.get("species", []):
-            # There is no need to also test "nattached",
-            # since a Species validator makes sure either both are present or both are None.
-            if getattr(species, "attached", None) is not None:
-                if StructureFeatures.SITE_ATTACHMENTS not in v:
+        elif StructureFeatures.ASSEMBLIES in v:
+            raise ValueError(
+                f"{StructureFeatures.ASSEMBLIES.value} MUST NOT be present, "
+                "since the property of the same name is not present"
+            )
+
+        if values.get("species"):
+            # disorder
+            for species in values.get("species", []):
+                if len(species.chemical_symbols) > 1:
+                    if StructureFeatures.DISORDER not in v:
+                        raise ValueError(
+                            f"{StructureFeatures.DISORDER.value} MUST be present when any one entry in species "
+                            "has a chemical_symbols list greater than one element"
+                        )
+                    break
+            else:
+                if StructureFeatures.DISORDER in v:
                     raise ValueError(
-                        f"{StructureFeatures.SITE_ATTACHMENTS.value} MUST be present when any one entry "
-                        "in species includes attached and nattached"
+                        f"{StructureFeatures.DISORDER.value} MUST NOT be present, since all species' chemical_symbols "
+                        "lists are equal to or less than one element"
                     )
-                break
-        else:
-            if StructureFeatures.SITE_ATTACHMENTS in v:
-                raise ValueError(
-                    f"{StructureFeatures.SITE_ATTACHMENTS.value} MUST NOT be present, since no species includes "
-                    "the attached and nattached fields"
-                )
-        # implicit_atoms
-        species_names = [_.name for _ in values.get("species", [])]
-        for name in species_names:
-            if name not in values.get("species_at_sites", []):
-                if StructureFeatures.IMPLICIT_ATOMS not in v:
+            # site_attachments
+            for species in values.get("species", []):
+                # There is no need to also test "nattached",
+                # since a Species validator makes sure either both are present or both are None.
+                if getattr(species, "attached", None) is not None:
+                    if StructureFeatures.SITE_ATTACHMENTS not in v:
+                        raise ValueError(
+                            f"{StructureFeatures.SITE_ATTACHMENTS.value} MUST be present when any one entry "
+                            "in species includes attached and nattached"
+                        )
+                    break
+            else:
+                if StructureFeatures.SITE_ATTACHMENTS in v:
                     raise ValueError(
-                        f"{StructureFeatures.IMPLICIT_ATOMS.value} MUST be present when any one entry in species "
-                        "is not represented in species_at_sites"
+                        f"{StructureFeatures.SITE_ATTACHMENTS.value} MUST NOT be present, since no species includes "
+                        "the attached and nattached fields"
                     )
-                break
-        else:
-            if StructureFeatures.IMPLICIT_ATOMS in v:
-                raise ValueError(
-                    f"{StructureFeatures.IMPLICIT_ATOMS.value} MUST NOT be present, since all species are "
-                    "represented in species_at_sites"
-                )
+            # implicit_atoms
+            species_names = [_.name for _ in values.get("species", [])]
+            for name in species_names:
+                if values.get(
+                    "species_at_sites"
+                ) is not None and name not in values.get("species_at_sites", []):
+                    if StructureFeatures.IMPLICIT_ATOMS not in v:
+                        raise ValueError(
+                            f"{StructureFeatures.IMPLICIT_ATOMS.value} MUST be present when any one entry in species "
+                            "is not represented in species_at_sites"
+                        )
+                    break
+            else:
+                if StructureFeatures.IMPLICIT_ATOMS in v:
+                    raise ValueError(
+                        f"{StructureFeatures.IMPLICIT_ATOMS.value} MUST NOT be present, since all species are "
+                        "represented in species_at_sites"
+                    )
+
         return v
 
 
diff --git a/optimade/server/warnings.py b/optimade/server/warnings.py
index 18f432d7..7ce40c8b 100644
--- a/optimade/server/warnings.py
+++ b/optimade/server/warnings.py
@@ -37,3 +37,8 @@ class TooManyValues(OptimadeWarning):
 
 class QueryParamNotUsed(OptimadeWarning):
     """A query parameter is not used in this request."""
+
+
+class MissingExpectedField(OptimadeWarning):
+    """A field was provided with a null value when a related field was provided
+    with a value."""


Test patch:
diff --git a/tests/models/test_data/test_bad_structures.json b/tests/models/test_data/test_bad_structures.json
index 1204198b..13da97d9 100644
--- a/tests/models/test_data/test_bad_structures.json
+++ b/tests/models/test_data/test_bad_structures.json
@@ -1503,7 +1503,13 @@
       "O",
       "O"
     ],
-    "structure_features": ["assemblies"],
+    "assemblies": [
+      {
+        "sites_in_groups": [ [0], [1], [2] ],
+        "group_probabilities": [0.3, 0.5, 0.2]
+      }
+    ],
+    "structure_features": [],
     "task_id": "mpf_276"
   },
   {
@@ -2402,7 +2408,7 @@
         "group_probabilities": [0.3, 0.5, 0.2]
       }
     ],
-    "structure_features": ["assemblies"]
+    "structure_features": []
   },
   {
     "task_id": "db/1234567",
diff --git a/tests/models/test_structures.py b/tests/models/test_structures.py
index 2828c608..84979385 100644
--- a/tests/models/test_structures.py
+++ b/tests/models/test_structures.py
@@ -1,9 +1,11 @@
 # pylint: disable=no-member
 import pytest
+import itertools
 
 from pydantic import ValidationError
 
-from optimade.models.structures import StructureResource
+from optimade.models.structures import StructureResource, CORRELATED_STRUCTURE_FIELDS
+from optimade.server.warnings import MissingExpectedField
 
 
 MAPPER = "StructureMapper"
@@ -19,6 +21,33 @@ def test_good_structures(mapper):
         StructureResource(**mapper(MAPPER).map_back(structure))
 
 
+@pytest.mark.filterwarnings("ignore", category=MissingExpectedField)
+def test_good_structure_with_missing_data(mapper, good_structure):
+    """Check deserialization of well-formed structure used
+    as example data with all combinations of null values
+    in non-mandatory fields.
+    """
+    structure = {field: good_structure[field] for field in good_structure}
+
+    # Have to include `assemblies` here, although it is only optional,
+    # `structure_features = ['assemblies']` in the test document so it
+    # is effectively mandatory
+    mandatory_fields = ("id", "type", "structure_features", "assemblies")
+
+    total_fields = [
+        field
+        for field in structure["attributes"].keys()
+        if field not in mandatory_fields
+    ]
+    for r in range(len(total_fields)):
+        for f in itertools.combinations(total_fields, r=r):
+            incomplete_structure = {field: structure[field] for field in structure}
+            for field in f:
+                incomplete_structure["attributes"][field] = None
+
+            StructureResource(**incomplete_structure)
+
+
 def test_more_good_structures(good_structures, mapper):
     """Check well-formed structures with specific edge-cases"""
     for index, structure in enumerate(good_structures):
@@ -27,7 +56,7 @@ def test_more_good_structures(good_structures, mapper):
         except ValidationError:
             # Printing to keep the original exception as is, while still being informational
             print(
-                f"Good test structure {index} failed to validate from 'test_more_structures.json'"
+                f"Good test structure {index} failed to validate from 'test_good_structures.json'"
             )
             raise
 
@@ -36,7 +65,9 @@ def test_bad_structures(bad_structures, mapper):
     """Check badly formed structures"""
     for index, structure in enumerate(bad_structures):
         # This is for helping devs finding any errors that may occur
-        print(f"Trying structure number {index} from 'test_bad_structures.json'")
+        print(
+            f"Trying structure number {index}/{len(bad_structures)} from 'test_bad_structures.json'"
+        )
         with pytest.raises(ValidationError):
             StructureResource(**mapper(MAPPER).map_back(structure))
 
@@ -139,7 +170,7 @@ deformities = (
 
 
 @pytest.mark.parametrize("deformity", deformities)
-def test_structure_deformities(good_structure, deformity):
+def test_structure_fatal_deformities(good_structure, deformity):
     """Make specific checks upon performing single invalidating deformations
     of the data of a good structure.
 
@@ -153,3 +184,21 @@ def test_structure_deformities(good_structure, deformity):
     good_structure["attributes"].update(deformity)
     with pytest.raises(ValidationError, match=fr".*{re.escape(message)}.*"):
         StructureResource(**good_structure)
+
+
+minor_deformities = (
+    {f: None} for f in set(f for _ in CORRELATED_STRUCTURE_FIELDS for f in _)
+)
+
+
+@pytest.mark.parametrize("deformity", minor_deformities)
+def test_structure_minor_deformities(good_structure, deformity):
+    """Make specific checks upon performing single minor invalidations
+    of the data of a good structure that should emit warnings.
+    """
+    if deformity is None:
+        StructureResource(**good_structure)
+    else:
+        good_structure["attributes"].update(deformity)
+        with pytest.warns(MissingExpectedField):
+            StructureResource(**good_structure)