Skip to content

Commit 6da5be7

Browse files
author
Félix Rohrlich
committed
fix: ref attribute is not required when it references an object currently being created via the 'bulkId:' prefix
1 parent 41de870 commit 6da5be7

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎scim2_models/base.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ def enforce_scim_context(self, info: ValidationInfo) -> Self:
445445
if Context.is_request(scim_context):
446446
if field_name in fields_set:
447447
self._check_mutability(field_name, scim_context)
448-
if is_create_or_replace:
448+
if is_create_or_replace and not self._is_unresolved_bulk_reference(
449+
field_name, scim_context
450+
):
449451
self._check_necessity(field_name, value)
450452
else:
451453
# Must be response
@@ -456,6 +458,29 @@ def enforce_scim_context(self, info: ValidationInfo) -> Self:
456458

457459
return self
458460

461+
def _is_unresolved_bulk_reference(
462+
self, field_name: str, scim_context: Context
463+
) -> bool:
464+
"""Whether a required Reference field targets a resource still being created.
465+
466+
:rfc:`RFC7644 §3.7.2 <7644#section-3.7.2>` lets one bulk operation
467+
reference a resource another operation in the same request is still
468+
creating, via a ``"bulkId:"``-prefixed placeholder in the sibling
469+
``value`` attribute (e.g. ``manager.value``). That reference's URI
470+
can only be resolved once the target exists, so a required Reference
471+
sub-attribute (e.g. ``manager.$ref``) isn't checked for necessity in
472+
this one documented case.
473+
"""
474+
if scim_context != Context.BULK_REQUEST:
475+
return False
476+
477+
root_type = self.__class__.get_field_root_type(field_name)
478+
if not (isclass(root_type) and issubclass(root_type, Reference)):
479+
return False
480+
481+
sibling_value = getattr(self, "value", None)
482+
return isinstance(sibling_value, str) and sibling_value.startswith("bulkId:")
483+
459484
def _raise_field_error(
460485
self, field_name: str, error: PydanticCustomError
461486
) -> NoReturn:

0 commit comments

Comments
 (0)