Skip to content

Commit

Permalink
fix(matrix-service): correct implementation of `ISimpleMatrixService.…
Browse files Browse the repository at this point in the history
…get_matrix_id`
  • Loading branch information
laurent-laporte-pro committed Mar 15, 2024
1 parent 019f2bd commit 51b9a46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion antarest/matrixstore/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ def get_matrix_id(self, matrix: t.Union[t.List[t.List[float]], str]) -> str:
Raises:
TypeError: If the provided matrix is neither a matrix nor a link to a matrix.
"""
# noinspection SpellCheckingInspection
if isinstance(matrix, str):
return matrix.lstrip("matrix://")
# str.removeprefix() is not available in Python 3.8
prefix = "matrix://"
if matrix.startswith(prefix):
return matrix[len(prefix) :]
return matrix
elif isinstance(matrix, list):
return self.create(matrix)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ def _create_diff(self, other: "ICommand") -> t.List["ICommand"]:

matrix_service = self.command_context.matrix_service
for matrix_name in ["values", "less_term_matrix", "equal_term_matrix", "greater_term_matrix"]:
self_matrix = getattr(self, matrix_name)
other_matrix = getattr(other, matrix_name)
if self_matrix != other_matrix:
args[matrix_name] = matrix_service.get_matrix_id(other_matrix)
self_matrix = getattr(self, matrix_name) # matrix, ID or `None`
other_matrix = getattr(other, matrix_name) # matrix, ID or `None`
self_matrix_id = None if self_matrix is None else matrix_service.get_matrix_id(self_matrix)
other_matrix_id = None if other_matrix is None else matrix_service.get_matrix_id(other_matrix)
if self_matrix_id != other_matrix_id:
args[matrix_name] = other_matrix_id

return [UpdateBindingConstraint(**args)]

0 comments on commit 51b9a46

Please sign in to comment.