inveniosoftware / invenio-records-rest

Invenio records REST API module.
https://invenio-records-rest.readthedocs.io
MIT License
4 stars 62 forks source link

Rollback if indexing fails #248

Closed ppanero closed 2 years ago

ppanero commented 5 years ago

Currently the creation of the record in the DB is committed before the indexing happens:

record = self.record_class.create(data, id_=record_uuid)
db.session.commit()

# Index the record
if self.indexer_class:
     self.indexer_class().index(record)

Source: https://github.com/inveniosoftware/invenio-records-rest/blob/master/invenio_records_rest/views.py#L601

Since the result of the indexing is not checked if for some reason Elasticsearch/Whatever other custom indexer fails to do so the record would be in the database already (which is not communicated to the user).

Should this be taken care of here? Or in an error handler?

lnielsen commented 5 years ago

By indexing before committing, you'll just end up with another problem with records appearing in the index but not in the database so I'm not sure this is a good idea

ppanero commented 2 years ago

clearly not a good idea 😅, DB should be the "source of truth". The only thing would be to report the indexing fails (which should happen anyway via sentry since there will be an exception)