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

Required extensions #77

Open
azmeuk opened this issue Sep 20, 2024 · 0 comments
Open

Required extensions #77

azmeuk opened this issue Sep 20, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@azmeuk
Copy link
Contributor

azmeuk commented Sep 20, 2024

Due to the following code, extension payload is required in resource creation payloads:
https://github.com/yaal-coop/scim2-models/blob/972bd8f01c157fc5720d90461e60d5da26fb7748/scim2_models/rfc7643/resource.py#L139

>>> from scim2_models import User, EnterpriseUser, Context
>>> payload = {
...     "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
...     "id": "new-user",
...     "userName": "new-user@example.com",
...     "meta": {
...         "resourceType": "User",
...         "created": "2010-01-23T04:56:22Z",
...         "lastModified": "2011-05-13T04:42:34Z",
...         "version": 'W\\/"3694e05e9dff590"',
...         "location": "http://localhost:46459/Users/new-user",
...     },
... }
>>> User[EnterpriseUser].model_validate(
...     payload, scim_ctx=Context.RESOURCE_CREATION_RESPONSE
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eloi/dev/yaal/scim2-models/scim2_models/base.py", line 661, in model_validate
    return super().model_validate(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eloi/.cache/pypoetry/virtualenvs/scim2-models-TH2HRh4a-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 595, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for User[EnterpriseUser]
  Field 'EnterpriseUser' has returnability 'always' but value is missing or null [type=returned_error, input_value={'schemas': ['urn:ietf:pa...:46459/Users/new-user'}}, input_type=dict]

However it feels like in some cases this code should be OK.

RFC7643 §6 indicates that sometimes extensions are required, and sometimes they are optional:

 required  A Boolean value that specifies whether or not the schema
    extension is required for the resource type.  If true, a
    resource of this type MUST include this schema extension and
    also include any attributes declared as required in this schema
    extension.  If false, a resource of this type MAY omit this
    schema extension.  REQUIRED.

scim2-models should offer a way to mark extensions to be required or optional.
In the meantime, a good default could be to consider extensions as optional, so the previous code would work.

@azmeuk azmeuk added the bug Something isn't working label Sep 20, 2024
@azmeuk azmeuk changed the title Validate payloads without extension part in resource creation context Required extensions Sep 20, 2024
@azmeuk azmeuk added enhancement New feature or request and removed bug Something isn't working labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant