|
46 | 46 | )
|
47 | 47 | from kpi.deployment_backends.mixin import DeployableMixin
|
48 | 48 | from kpi.exceptions import (
|
| 49 | + AssetAdjustContentError, |
49 | 50 | BadPermissionsException,
|
50 | 51 | DeploymentDataException,
|
51 | 52 | )
|
@@ -698,13 +699,34 @@ def save(
|
698 | 699 | )
|
699 | 700 | return
|
700 | 701 |
|
| 702 | + update_content_field = update_fields and 'content' in update_fields |
| 703 | + |
| 704 | + # Raise an exception if we want to adjust asset content |
| 705 | + # (i.e. `adjust_content` is True) but we are trying to update only |
| 706 | + # certain fields and `content` is not part of them, or if we |
| 707 | + # specifically ask to not adjust asset content, but trying to |
| 708 | + # update only certain fields and `content` is one of them. |
| 709 | + if ( |
| 710 | + (adjust_content and update_fields and 'content' not in update_fields) |
| 711 | + or |
| 712 | + (not adjust_content and update_content_field) |
| 713 | + ): |
| 714 | + raise AssetAdjustContentError |
| 715 | + |
| 716 | + # If `content` is part of the updated fields, `summary` and |
| 717 | + # `report_styles` must be too. |
| 718 | + if update_content_field: |
| 719 | + update_fields += ['summary', 'report_styles'] |
| 720 | + # Avoid duplicates |
| 721 | + update_fields = list(set(update_fields)) |
| 722 | + |
701 | 723 | # `self.content` must be the second condition. We do not want to get
|
702 | 724 | # the value of `self.content` if first condition is false.
|
703 | 725 | # The main purpose of this is avoid to load `self.content` when it is
|
704 | 726 | # deferred (see `AssetNestedObjectViewsetMixin.asset`) and does not need
|
705 | 727 | # to be updated.
|
706 | 728 | if (
|
707 |
| - (not update_fields or update_fields and 'content' in update_fields) |
| 729 | + (not update_fields or update_content_field) |
708 | 730 | and self.content is None
|
709 | 731 | ):
|
710 | 732 | self.content = {}
|
|
0 commit comments