Skip to content

BUG: fixed _write method for sqlite to avoid repeated encoding of parameter dictionary

When using the update function of the db module, the _write method of the SQLite3Database is repeatedly called to write the updated row to the database. In the previous version the calculator parameters (row.calculator_parameters) were re-encoded every time, which led to the corresponding field to grow with every call of the update method. More precisely, when the record was written for the first time, calling the encode method from ase/io/jsonio.py turned the calculator_parameters dictionary into a string. During each call to _write that followed this string was re-encoded, leading an every increasing number of backslashes for escaping quotation marks. In the modified version the calculator_parameter is now only encoded if it is not already a string, which circumvents the afore-described problem.

One might ask whether this is a more general problem that should/could be captured at a more fundamental level as it might affect other functionality as well.

Before committing I ran ase/db/sqlite.py through pep8/pyflakes and removed trailing white spaces to obtain compliance.

Merge request reports