After further analysis, I noticed that Postgres was receiving a ROLLBACK query every time the sync_with_external method was being called. So the problem wasn´t the write() method.
Finally the culprit was a line of code at the end of the custom method:
raise exceptions.Warning(_("Customer synced successfully"))
I thought raising a Warning was innocent enough to be used just to display a success message to the user. Little I knew this was going to cost me several days of rethinking my life choices and almost falling into insanity.
I hope this helps anyone that may fall into this same issue.
Why don't you use
self.external_id = res['id']
Are you also certain that the method sync_with_external is being executed and that res['id'] is not None. I hope this helps.
I think you need to change the field name.
Reason: Odoo already external id field in import and export data.
Already tried another field name, but same results