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
8 stars 21 forks source link

Create migration for pickle fields to save data in JSON #159

Open cmutel opened 7 months ago

cmutel commented 7 months ago

Storing data in pickle fields is a security issue. We should use JSON with a datetime-aware encoder instead. To do this, we need to work with the constraints of SQLite (where we can't just add a column easily). We also need a script step added in updates, and a test fixture of a project directory (created with bw2io.backup_project_directory where we can apply the migration.

Data first needs to be loaded from the pickled columns and tested to make sure it can be serialized to JSON (i.e. no functions or executable code, just basic data types). If this condition is violated an error should be raised.

I think all the pickle fields are in https://github.com/brightway-lca/brightway2-data/blob/main/bw2data/backends/schema.py, but this needs to be checked.