Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlexMeasures CLI complains about an asset being added to an account if there is already a public asset with the same name #728

Closed
nhoening opened this issue Jun 15, 2023 · 1 comment

Comments

@nhoening
Copy link
Contributor

I found that FM complains about an asset being added to an account if there is already a public asset with the same name (I added two debug logs for clarity, "New asset data:" and "Found asset:"):

± flexmeasures add asset --name Something --account-id 1 --asset-type-id 2
[FLEXMEASURES][2023-06-15 13:06:02,580] INFO: Loading config from /home/nicolas/.flexmeasures.cfg ...
Warning: Without complete redis connection settings, FlexMeasures will not be able to run forecasting and scheduling job queues.
Warning: Without complete mail settings, FlexMeasures will not be able to send mails to users, e.g. for password resets!
You might consider setting MAIL_USERNAME, MAIL_PASSWORD, FLEXMEASURES_REDIS_PASSWORD.
[FLEXMEASURES][2023-06-15 13:06:03,213] INFO: Loaded plugins: {}
New asset data: {'name': 'Something', 'latitude': None, 'longitude': None, 'generic_asset_type_id': 2, 'account_id': 1}
Found asset: <GenericAsset 37: 'Something' (wind)> with account_id: None ...
Please correct the following errors:
{'name': ['An asset with the name Something already exists in this account.']}.
 Use the --help flag to learn more.
Aborted!

I feel that the query in data/schemas/generic_assets.py (line 52) looks okay, currently I don't know why the public asset is found:

    asset = GenericAsset.query.filter(
        GenericAsset.name == data["name"]
        and GenericAsset.account_id == data["account_id"]
    ).one_or_none()

Originally posted by @nhoening in #727 (comment)

nhoening added a commit that referenced this issue Jun 15, 2023
… special case for public assets (#728)#

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Flix6x added a commit that referenced this issue Jun 15, 2023
…also add special case for public assets (#728)#"

This reverts commit ba278b1.
Flix6x pushed a commit that referenced this issue Jun 15, 2023
… special case for public assets (#728)#

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
nhoening added a commit that referenced this issue Jun 15, 2023
* feat: Allow adding public assets through the CLI

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: CLI changelog entry

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: update help string

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: add missing CLI changelog entries

Signed-off-by: F.N. Claessen <felix@seita.nl>

* docs: add release date

Signed-off-by: F.N. Claessen <felix@seita.nl>

* add warning if a public asset has been created

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* fix wrong query setup in validate_name_is_unique_in_account, also add special case for public assets (#728)#

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* Revert "fix wrong query setup in validate_name_is_unique_in_account, also add special case for public assets (#728)#"

This reverts commit ba278b1.

* The `and` statement was not working as intended. Also, using `first` is more robust against duplicate asset names already being present in the database.

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Revert "The `and` statement was not working as intended. Also, using `first` is more robust against duplicate asset names already being present in the database."

This reverts commit 64b9632.

* fix wrong query setup in validate_name_is_unique_in_account, also add special case for public assets (#728)#

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* Using first is more robust against duplicate asset names already being present in the database.

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Simplify if-statement

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Note the user-facing CLI option in the help string

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: F.N. Claessen <felix@seita.nl>
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
Co-authored-by: Nicolas Höning <nicolas@seita.nl>
@nhoening
Copy link
Contributor Author

Fixed by #727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant