LCA-ActivityBrowser / activity-browser

GUI for brightway2
GNU Lesser General Public License v3.0
149 stars 57 forks source link

New peewee syntax in bw2data 3.3 #135

Closed haasad closed 6 years ago

haasad commented 6 years ago

Brightway was updated to work with the new peewee 3 syntax yesterday, which now requires some changes in the AB as well. Currently new installs of the AB fail with the following error:

...
 File "/home/travis/build/LCA-ActivityBrowser/activity-browser/activity_browser/app/controller.py", line 8, in <module>
    from bw2data.project import ProjectDataset, create_database
ImportError: cannot import name 'create_database'

example failing build: https://travis-ci.org/LCA-ActivityBrowser/activity-browser/jobs/363072807

haasad commented 6 years ago

This is fixed in #136.

@bsteubing, could you please check if this works for you (and reopen the issue if it doesn't)? The changes only touch the part about the custom brigthway dirpath, which you use.

FYI: I also had to make a hotfix release (2.2.4), because 2.2.3 was already throwing errors again, because of the new brightway API.

bsteubing commented 6 years ago

@haasad: sorry, was still broken... I commented out in L86 in controller: bw.projects.db.close()

bsteubing commented 6 years ago

Also, there are a number of peewee errors:

Loading project: ei34
Traceback (most recent call last):
  File "C:\Users\steubingbrp\AppData\Local\Continuum\miniconda3\envs\py3\lib\site-packages\peewee.py", line 5534, in get
    return clone.execute()[0]
  File "C:\Users\steubingbrp\AppData\Local\Continuum\miniconda3\envs\py3\lib\site-packages\peewee.py", line 3396, in __getitem__
    return self.row_cache[item]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\steubingbrp\surfdrive\Leiden\python\GitHub\LCA-ActivityBrowser\activity-browser\activity_browser\app\ui\tables\LCA_setup.py", line 86, in sync
    self.append_row(key, str(amount))
  File "C:\Users\steubingbrp\surfdrive\Leiden\python\GitHub\LCA-ActivityBrowser\activity-browser\activity_browser\app\ui\tables\LCA_setup.py", line 64, in append_row
    act = bw.get_activity(key)
  File "C:\Users\steubingbrp\AppData\Local\Continuum\miniconda3\envs\py3\lib\site-packages\bw2data\utils.py", line 332, in get_activity
    return Database(key[0]).get(key[1])
  File "C:\Users\steubingbrp\AppData\Local\Continuum\miniconda3\envs\py3\lib\site-packages\bw2data\backends\peewee\database.py", line 133, in get
    ActivityDataset.code == code).get()
  File "C:\Users\steubingbrp\AppData\Local\Continuum\miniconda3\envs\py3\lib\site-packages\peewee.py", line 5539, in get
    (clone.model, sql, params))
bw2data.backends.peewee.schema.ActivityDatasetDoesNotExist: <class 'bw2data.backends.peewee.schema.ActivityDataset'> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT 1 OFFSET 0
Params: ['test1', '60f4b8aaae24c16500e23ce50280705e']

Loaded project: ei34
Loading project: default
Traceback (most recent call last):
  File "C:\Users\steubingbrp\surfdrive\Leiden\python\GitHub\LCA-ActivityBrowser\activity-browser\activity_browser\app\ui\tables\LCA_setup.py", line 79, in sync
    self.cellChanged.disconnect(self.filter_amount_change)
TypeError: 'method' object is not connected

Loaded project: default
Loading project: ei34
Traceback (most recent call last):
  File "C:\Users\steubingbrp\surfdrive\Leiden\python\GitHub\LCA-ActivityBrowser\activity-browser\activity_browser\app\ui\tables\LCA_setup.py", line 79, in sync
    self.cellChanged.disconnect(self.filter_amount_change)
TypeError: 'method' object is not connected

Loaded project: ei34
haasad commented 6 years ago

You have peewee=3.1.5 and bw2data=3.3 in your env now, right?

It appears that this only affects the switch_brightway2_dir_path part, right? Any chance that we can get rid of your old implementation and work with the BRIGHTWAY2_DIR env variable like described here? This would need to be set before we import brightway and would require a restart of the AB when changed in the settings. But the advantage is that the problem is "outsourced" to brightway.

haasad commented 6 years ago

I looks like your changes broke the default bw_path: image I can only get the dbs to display after switching to a custom path and restoring the defaults, can't reproduce your peewee errors above. Any idea what's going on?