Closed azmeuk closed 3 months ago
Currently, on model validation a check is performed to detect model extension attributes, and use setattr to assign the new value.
setattr
https://github.com/yaal-coop/scim2-models/blob/d32a5c2a4b62c27eddba12c94d6ab53bc0de1974/scim2_models/rfc7643/resource.py#L176-L178
We should investigate how to dynamically build the new pydantic field based on models type parameters, at the model definition time instead of validation.
This may allow to forbid extra fields:
https://github.com/yaal-coop/scim2-models/blob/d32a5c2a4b62c27eddba12c94d6ab53bc0de1974/scim2_models/rfc7643/resource.py#L92-L93
Good candidates for implementing this are metaclasses, __initsubclass_\.
Currently, on model validation a check is performed to detect model extension attributes, and use
setattr
to assign the new value.https://github.com/yaal-coop/scim2-models/blob/d32a5c2a4b62c27eddba12c94d6ab53bc0de1974/scim2_models/rfc7643/resource.py#L176-L178
We should investigate how to dynamically build the new pydantic field based on models type parameters, at the model definition time instead of validation.
This may allow to forbid extra fields:
https://github.com/yaal-coop/scim2-models/blob/d32a5c2a4b62c27eddba12c94d6ab53bc0de1974/scim2_models/rfc7643/resource.py#L92-L93
Good candidates for implementing this are metaclasses, __initsubclass_\.