activity-browser icon indicating copy to clipboard operation
activity-browser copied to clipboard

Duplicating activities does not add the original database to 'Depends' column.

Open marc-vdm opened this issue 3 years ago • 1 comments

When an activity is duplicated to another database. The Depends column does not update to reflect the new dependency. Changing the project or closing/opening AB does not fix this.

marc-vdm avatar Feb 14 '22 14:02 marc-vdm

Problem is worse, AB also doesn't update Depends column when exchanges from other databases are added.

Additional info: The sync of DatabasesModel reads the dependencies from Brightway. The issue is in AB apparently failing to update this dependency in BW. By checking bw.databases[name].get("depends", []) I found that it is not a UI problem but that the actual bw dependency is not updated.

Updating is failing to happen in 5 instances:

  1. Adding an exchange from database A to database !A (dependency should be added to A)
  2. Removing an exchange from database A from an activity in database !A (dependency from A should be removed)
  3. Duplicating an activity which has dependencies from database !A to database A (should add dependency to A)
  4. Deleting an activity in database A, which has dependencies from !A (dependencies to !A should be removed)
  5. Deleting an activity in database A with downstream consumers in database !A (dependencies of !A should be updated)
  6. potentially related: #1012

All these updates should happen in activity.py, specifically in relevant function of ActivityController and ExchangeController. Additionally, an update signal should probably be added in __init__ of the table model for signals.database_changed.connect(self.sync)

When re-linking a database, the depends column gets updated properly (here).

I haven't found yet what the reason is for this failing update or why it is updating on relink.

Perhaps we need bw.Database(db).find_dependents() though from testing this seems to not always be the full solution (only works when adding, not removing?). However, this call is also not included for relinking*, so I'm not sure why it does work there. A slight warning about bw.Database(db).find_dependents() though: This will check the entire database db, this can take a very long time for large databases.

* well, it is, but before we make changes during relinking, so it seems similar to a check like bw.databases[name].get("depends", [])?

marc-vdm avatar Feb 18 '22 20:02 marc-vdm