gramps-project / gramps-web-api

A RESTful web API for Gramps - backend of Gramps Web
https://www.grampsweb.org
GNU Affero General Public License v3.0
84 stars 46 forks source link

Gramps XML export (and thus synchronization) can fail in case of corrupted objects #479

Open DavidMStraub opened 10 months ago

DavidMStraub commented 10 months ago

If some objects contain invalid data, such as None as handle, Gramps XML export can fail, which prevents backup as well as synchronization. We should have something like a "repair database" endpoint.

DavidMStraub commented 10 months ago

The best solution would of course be to just use the Gramps built-in check & repair tool, however that does not work since it also tries to check media checksums, which generally will not for in Web API because media files are managed differently.

~So the best solution for now in my opinion would be to create a new addon that is a ligher (or customizable) version of check.py, but not reimplementing any of the logic.~

On second though, I think an addon is overkill - we can just create a background task that runs the functions in the check and repair tool except media checksums.

DavidMStraub commented 10 months ago

Example traceback:

  File "/usr/lib/python3/dist-packages/gramps/plugins/export/exportxml.py", line 179, in write
    self.write_xml_data()
  File "/usr/lib/python3/dist-packages/gramps/plugins/export/exportxml.py", line 313, in write_xml_data
    self.write_source(source,2)
  File "/usr/lib/python3/dist-packages/gramps/plugins/export/exportxml.py", line 616, in write_source
    self.write_media_list(source.get_media_list(), index+1)
  File "/usr/lib/python3/dist-packages/gramps/plugins/export/exportxml.py", line 1129, in write_media_list
    self.g.write('%s<objref hlink="%s"' % (sp,"_"+mobj_id))
                                              ~~~^~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
DavidMStraub commented 10 months ago

To be confirmed whether this is actually fixed.

DavidMStraub commented 9 months ago

Confirmed by the user that the issue is not fixed - media references with ref None still cause this error after running check & repair.