Skip to content

Commit

Permalink
Enhance stored file handling with single reference validation
Browse files Browse the repository at this point in the history
Added support for `SingleReferenceValidator` to enforce single-file references when defined. This ensures the property will only store one file if the validator is active, improving data consistency.
  • Loading branch information
Jochem Berends committed Jan 22, 2025
1 parent 65ad90f commit f893b69
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pykechain/models/property_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pykechain.models.form import Form
from pykechain.models.input_checks import check_enum
from pykechain.models.stored_file import StoredFile
from pykechain.models.validators import SingleReferenceValidator
from pykechain.models.value_filter import ScopeFilter
from pykechain.models.workflow import Status
from pykechain.utils import get_in_chunks, uniquify
Expand Down Expand Up @@ -357,15 +358,17 @@ def upload(self, data: Any) -> None:
:raises OSError: When the path to the file is incorrect or file could not be found
"""
filename = os.path.basename(data)
stored_file = self._client.create_stored_file(
new_stored_file = self._client.create_stored_file(
name=filename,
scope=self.scope,
classification=StoredFileClassification.SCOPED,
category=StoredFileCategory.REFERENCED,
filepath=data,
)
self.value = self.value + [stored_file] if self.value else [stored_file]

if self.has_validator(SingleReferenceValidator):
self.value = [new_stored_file]
else:
self.value = self.value + [new_stored_file] if self.value else [new_stored_file]

class SignatureProperty(_ReferenceProperty):
"""A virtual object representing a KE-chain StoredFile References property."""
Expand Down

0 comments on commit f893b69

Please sign in to comment.