brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
10 stars 24 forks source link

Incomprehensible error with `make_searchable` on new database #30

Closed aleksandra-kim closed 8 years ago

aleksandra-kim commented 8 years ago

Original report by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Current error is e.g.

#!python

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-30-8e5992c4fb52> in <module>()
      1 db = Database("biosphere2")
----> 2 db.make_searchable()

/Users/cmutel/local35/bw3/lib/python3.5/site-packages/bw2data/project.py in writable_project(wrapped, instance, args, kwargs)
    298     if projects.read_only:
    299         raise ReadOnlyProject(READ_ONLY_PROJECT)
--> 300     return wrapped(*args, **kwargs)

/Users/cmutel/local35/bw3/lib/python3.5/site-packages/bw2data/backends/peewee/database.py in make_searchable(self)
    276             print("This database is already searchable")
    277             return
--> 278         databases[self.name]['searchable'] = True
    279         databases.flush()
    280         IndexManager(self.filename).add_datasets(self)

/Users/cmutel/local35/bw3/lib/python3.5/site-packages/bw2data/serialization.py in __getitem__(self, key)
    140         if isinstance(key, list):
    141             key = tuple(key)
--> 142         return self.data[key]
    143 
    144     @writable_project

KeyError: 'biosphere2'

This should be clearer that the database doesn't exist, therefore can't be made searchable.

aleksandra-kim commented 8 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Fix #30. Better flow logic for make_searchable