Skip to content

Feat/copy assets#2017

Open
joshuaunity wants to merge 31 commits intomainfrom
feat/copy-assets
Open

Feat/copy assets#2017
joshuaunity wants to merge 31 commits intomainfrom
feat/copy-assets

Conversation

@joshuaunity
Copy link
Copy Markdown
Contributor

@joshuaunity joshuaunity commented Mar 11, 2026

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

  • Successfully Copy Asset to target asset
  • Write a test to confirm the above feature
  • Write a test to confirm that asset parents and children are accurate
  • Successfully copy assets and asset sensors and children to the target asset
  • Write a test to confirm the above feature
  • Successfully copy asset flexconfig... (I don't know how feasible this would be yet, maybe 80% ?)
  • Write a test to confirm the above feature

Look & Feel

None

How to test

Further Improvements

Related Items

This PR closes #1966

Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

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>
@joshuaunity joshuaunity requested a review from Flix6x March 11, 2026 11:45
@joshuaunity joshuaunity self-assigned this Mar 11, 2026
@joshuaunity joshuaunity added the enhancement New feature or request label Mar 11, 2026
@joshuaunity
Copy link
Copy Markdown
Contributor Author

CC @nhoening

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community bot commented Mar 11, 2026

Documentation build overview

📚 flexmeasures | 🛠️ Build #32235629 | 📁 Comparing 47a95bd against latest (8934f22)

  🔍 Preview build  

Show files changed (7 files in total): 📝 7 modified | ➕ 0 added | ➖ 0 deleted
File Status
changelog.html 📝 modified
genindex.html 📝 modified
http-routingtable.html 📝 modified
_autosummary/flexmeasures.api.common.utils.api_utils.html 📝 modified
_autosummary/flexmeasures.api.v3_0.assets.html 📝 modified
_autosummary/flexmeasures.data.services.data_sources.html 📝 modified
api/v3_0.html 📝 modified

@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Mar 11, 2026

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.

@nhoening
Copy link
Copy Markdown
Contributor

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.

  • The test can assert the first part first (e.g. assets and subassets are copied), and others later(sensors, flex-config are copied), so you can still follow along how far you are in kaking the test pass, layer by layer.
  • This way would be more helpful in understanding together if the scope is agreed between all of us. The test is easier to write (I suggest using AI to help) and to read than the actual implementation.

"20 \u00b0C",
"3 * 230V * 16A"
]
"description": "Quantity string describing a fixed quantity."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump

Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from Flix6x March 13, 2026 12:03
joshuaunity and others added 2 commits March 13, 2026 17:23
Signed-off-by: Joshua Edward <oghenerobojosh01@gmail.com>
Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from Flix6x March 18, 2026 09:51
Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments on the schema. I'll move to testing now.

Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to use Swagger for testing, but I don't see the new endpoint listed on http://localhost:5000/api/v3_0/docs/. I'm delaying testing until I can use that. If you need me to test without it, please provide instructions.

…s and query parameters

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
…ated

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Co-authored-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
@joshuaunity joshuaunity requested a review from nhoening March 30, 2026 13:18
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Apr 2, 2026

@joshuaunity Please fix the failing pipeline and update the PR description (2 todos still marked unresolved).

Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on an asset with sensors_to_show='[[309, 308], [305], [14, 14]]', where:

  • 309 is a sensor on original asset
  • sensors 308 and 305 are sensors on a child asset of the original asset
  • 14 is a sensor on a public asset

I was expecting the 30x sensor IDs to be replaced by new IDs, but they were copied verbatim.

@joshuaunity
Copy link
Copy Markdown
Contributor Author

I tested on an asset with sensors_to_show='[[309, 308], [305], [14, 14]]', where:

  • 309 is a sensor on original asset
  • sensors 308 and 305 are sensors on a child asset of the original asset
  • 14 is a sensor on a public asset

I was expecting the 30x sensor IDs to be replaced by new IDs, but they were copied verbatim.

Working on this

… graph

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

I tested on an asset with sensors_to_show='[[309, 308], [305], [14, 14]]', where:

  • 309 is a sensor on original asset
  • sensors 308 and 305 are sensors on a child asset of the original asset
  • 14 is a sensor on a public asset

I was expecting the 30x sensor IDs to be replaced by new IDs, but they were copied verbatim.

Working on this

@Flix6x you can test this out again.

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity joshuaunity requested a review from Flix6x April 9, 2026 19:07
@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Apr 10, 2026

@copilot please fix the failing pipeline on this PR branch. Do not make a new PR. Then, review this PR.

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

@copilot please fix the failing pipeline on this PR branch. Do not make a new PR. Then, review this PR.

Fixed in commit 3b8dd82. The CI failure was caused by unused Annotation and get_or_create_annotation imports (F401 flake8 errors). These were unused because the post_annotation function that uses them was accidentally dropped during the merge at commit 4e84d1f. I've restored the function, and all pre-commit hooks (flake8, black, mypy, OpenAPI spec generation) now pass.

Copy link
Copy Markdown
Contributor

@Flix6x Flix6x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, a lot works very well now. A few things left:

  • Regression: on opening the Edit Graphs modal, I get toast notifications showing "Unknown graph format: 124". It doesn't happen on main. Can you reproduce it?
  • I also had copilot fix the failing pipeline, but I still see the POST annotations endpoint being deleted from openapi-specs.json in this PR. I don't know why, please investigate.
  • When copying an asset twice, the second copy gets the same name as the first copy. I think subsequent copies should get a number, so:
    • Home
    • Home (Copy)
    • Home (Copy 2)
    • Home (Copy 3)
    • etc.
  • Please update the PR description.
  • Missing changelog entry.

]
}
},
"/api/v3_0/assets/{id}/annotations": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not disappear. See also #2017 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the make command, and this didnt get deleted

@joshuaunity
Copy link
Copy Markdown
Contributor Author

joshuaunity commented Apr 13, 2026

Regression: on opening the Edit Graphs modal, I get toast notifications showing "Unknown graph format: 124". It doesn't happen on main. Can you reproduce it?

What does your sensors_to_show look like on your DB

joshuaunity and others added 3 commits April 13, 2026 05:25
…ndpoint for asset annotations

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Apr 13, 2026

(I don't know how feasible this would be yet, maybe 80% ?)

Are we now at 100% or are there still cases where you expect copying flex-config to fail?

@Flix6x
Copy link
Copy Markdown
Contributor

Flix6x commented Apr 13, 2026

Regression: on opening the Edit Graphs modal, I get toast notifications showing "Unknown graph format: 124". It doesn't happen on main. Can you reproduce it?

What does your sensors_to_show look like on your DB

> select sensors_to_show from generic_asset where id=46;
   sensors_to_show    
----------------------
 [121, 122, 123, 124]

@joshuaunity
Copy link
Copy Markdown
Contributor Author

Regression: on opening the Edit Graphs modal, I get toast notifications showing "Unknown graph format: 124". It doesn't happen on main. Can you reproduce it?

What does your sensors_to_show look like on your DB

> select sensors_to_show from generic_asset where id=46;
   sensors_to_show    
----------------------
 [121, 122, 123, 124]

thanks

Signed-off-by: JDev <45713692+joshuaunity@users.noreply.github.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

Are we now at 100% or are there still cases where you expect copying flex-config to fail?

we are at 100% i would say, as of my tests on Friday, flex config was copied over nicely.

Signed-off-by: joshuaunity <oghenerobojosh01@gmail.com>
@joshuaunity
Copy link
Copy Markdown
Contributor Author

joshuaunity commented Apr 13, 2026

Regression: on opening the Edit Graphs modal, I get toast notifications showing "Unknown graph format: 124".

This is now fixed.

@Flix6x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copying assets

4 participants