-
Notifications
You must be signed in to change notification settings - Fork 527
[connectors-sdk] Add ObservedData to models (#5397) #5401
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
Conversation
3d61e60 to
2b9da75
Compare
mariot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect!
thanks for the tests
|
Thank you for your PR and good job for identifying this specific stix2 error for Observed Data ( I suggest a few adjustments even though the code works perfectly:
labels: list[str] | None = Field(
default=None,
description="Labels of the observed data",
)
associated_files: list[AssociatedFile] | None = Field(
default=None,
description="Files to upload with the observed data, e.g. observed data as a PDF.",
)The following fields are not added because they are already inherited from
PS: Although on the front end the Context: STIX error with ObservedDataHere is the specific STIX error that occurs when _check_mutually_exclusive_properties
raise MutuallyExclusivePropertiesError(self.__class__, list_of_properties)
stix2.exceptions.MutuallyExclusivePropertiesError: The (object_refs, objects) properties for ObservedData are mutually exclusive.When In our case:
Current error handling: def model_post_init(self, context__: Any) -> None:
"""Validate objects before calling id."""
if not self.objects:
raise ValueError("objects must contain at least one element")
super().model_post_init(context__)We obtain: pydantic_core._pydantic_core.ValidationError: 1 validation error for ObservedData
Value error, entities must contain at least one element
[type=value_error, input_value={'entities': [], 'first_o...', 'number_observed': 2}, input_type=dict]Two different suggestions:
entities: list[BaseIdentifiedEntity] = Field(
min_length=1,
description="List of OpenCTI identified entities observed.",
)We obtain: pydantic_core._pydantic_core.ValidationError: 1 validation error for ObservedData
entities
List should have at least 1 item after validation, not 0
[type=too_short, input_value=[], input_type=list]Simple and native, like the
@field_validator("entities")
@classmethod
def entities_must_not_be_empty(cls, value):
if not value:
raise ValueError("The 'entities' field must contain at least one element.")
return valueWe obtain: pydantic_core._pydantic_core.ValidationError: 1 validation error for ObservedData
entities
Value error, The 'entities' field must contain at least one element.
[type=value_error, input_value=[], input_type=list]Clear, business-oriented message (avoids a lower-level STIX error) Personally, like you, I prefer an explicit, business-oriented error message.
If we systematically choose clear business messages, then we should consider replacing certain native constraints with explicit validators for greater consistency. PS: We will probably need to adapt the tests! |
2b9da75 to
c29fc40
Compare
Megafredo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine with me! Well done!

Proposed changes
Related issues
Checklist
Further comments