Conversation
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
|
CC @nhoening |
|
Thank you for requesting a review. It looks like the scope of this PR may be mistaken? You are creating an endpoint to copy all assets under a given account*, rather than an endpoint to copy a given asset, including all assets under it. |
|
We can also discuss the test strategy. Joshua chose to implement a part of the solution, then tests for that, then the next part, test for that etc. I believe we suggested initially to have one test case that tests a complete successful copy, then work on making it pass.
|
| "20 \u00b0C", | ||
| "3 * 230V * 16A" | ||
| ] | ||
| "description": "Quantity string describing a fixed quantity." |
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Flix6x
left a comment
There was a problem hiding this comment.
Thanks @joshuaunity this is now heading in the right direction. See my comments for the next challenge: a deep copy. Just let me know if any decisions come up.
flexmeasures/api/v3_0/assets.py
Outdated
| if account is None: | ||
| resolved_account = asset.owner | ||
| resolved_parent = asset.parent_asset | ||
| else: | ||
| resolved_account = account | ||
| resolved_parent = parent_asset |
There was a problem hiding this comment.
Let's move this to the @post_load in the schema, too.
| assert first_copy.parent_asset_id == parent.id | ||
|
|
||
| # Second copy under the same parent fails: UNIQUE(name, parent_asset_id) is violated | ||
| # because parent_asset_id is non-NULL (PostgreSQL only treats NULLs as distinct). |
There was a problem hiding this comment.
PostgreSQL only treats NULLs as distinct
Interesting. So when coping twice to a NULL parent, would it be possible to then get two identically named top-level assets?
There was a problem hiding this comment.
The unique constraint only applies when there is an actual ID. If both assets are without a parent, they will be created without a problem.
| 3. flex_context is preserved verbatim (sensor IDs are unchanged). | ||
| 4. copy_asset is a *shallow* copy: the original child assets are not duplicated. |
There was a problem hiding this comment.
Great to see these kinds of explicit test expectations written up, thanks for that!
Assertions 3 and 4 are the opposite of what we desire, I think. That is, we want the feature to create a deep copy, by making new copies of child assets and new copies of (non-public) sensors anywhere in the underlying asset tree.
@nhoening one thing we haven't explicitly written up is whether the time series data would need to be copied, too. I vote no, to keep the scope at bay.
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
| }, | ||
| location="path", | ||
| ) | ||
| @as_json |
There was a problem hiding this comment.
Please also add a decorator here to check for read access (or whatever we named that) on the asset itself.
Description
This PR introduces an API allowing users to copy assets from one account to another, using the original account's assets as templates. The feature is currently in progress and being developed incrementally.
##TODO
Look & Feel
None
How to test
Further Improvements
Related Items
This PR closes #1966
Sign-off