Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] connector_search_engine: keep data for bindins to check #192

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions connector_search_engine/models/se_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def _recompute_json(self, force_export=False):
# be the same no matter the access rights of the user triggering this.
result = []
validation_errors = {}
to_be_checked = []
for work in self.sudo()._work_by_index():
mapper = work.component(usage="se.export.mapper")
for binding in work.records.with_context(
Expand All @@ -197,21 +196,19 @@ def _recompute_json(self, force_export=False):
error = self._validate_record(work, index_record)
if error:
validation_errors.setdefault(error, []).append(binding.id)
to_be_checked.append(binding.id)
# skip record
continue
if binding.data != index_record or force_export:
if binding.data != index_record or force_export or error:
vals = {"data": index_record}
if binding.sync_state != "to_update":
vals["sync_state"] = "to_update"
vals["date_modified"] = fields.Datetime.now()
if error:
vals["sync_state"] = "to_be_checked"
vals["data"]["__error__"] = error
Copy link
Contributor Author

@simahawk simahawk May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course it would be better to have a specific field. However:

  • we could have tons of records on different models
  • in a pre-migrate step you don't have at hand all the models that could inherit from the mixin as they are not loaded yet
  • we cannot safely add the field via sql to all the tables that would need it

Or, at least, I don't have a smart way to do it...
This is better than nothing for now :)

Any recommendation?

binding.write(vals)
if validation_errors:
result.append(
self._format_recompute_json_validation_errors(validation_errors)
)
if to_be_checked:
self.browse(to_be_checked).write({"sync_state": "to_be_checked"})
return "\n\n".join(result)

def _format_recompute_json_validation_errors(self, validation_errors):
Expand Down
3 changes: 3 additions & 0 deletions connector_search_engine/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ def test_recompute_json_to_be_checked(self):
"Validation errors:\n\n "
f"Something wrong with data - IDs: {self.partner_binding.id}",
)
self.assertEqual(
self.partner_binding.data["__error__"], "Something wrong with data"
)

def test_recompute_json_to_be_checked_rollback(self):
# If something was to check but it's now good,
Expand Down
Loading