2

I have a problem when using the l10n_es_aeat_sii_oca module. After a while I could locate the problem, and it is in this peace of code:

try:
    ...
except Exception as fault:
    new_cr = Registry(self.env.cr.dbname).cursor()
    env = api.Environment(new_cr, self.env.uid, self.env.context)
    document = env[document._name].browse(document.id)
    doc_vals.update({
        "aeat_send_failed": True,
        "aeat_send_error": repr(fault)[:60],
        "sii_return": repr(fault),
        "aeat_content_sent": json.dumps(inv_dict, indent=4),
    })
    document.write(doc_vals)
    new_cr.commit()
    new_cr.close()
    raise ValidationError(fault) from fault

If the exception is raised, a new cursor is created and the document values are modified through this new DB cursor. I don't know the reason for creating a new DB cursor, I guess this is in order to fill in the document fields with the values and avoid them to be removed by the ROLLBACK of the ValidationError, is that the reason?

The problem is that when the workflow reaches the line new_cr.commit(), it stops and stays loading forever. Why?

If I modify the code and do this:

try:
    ...
except Exception as fault:
    document = self.env[document._name].browse(document.id)
    doc_vals.update({
        "aeat_send_failed": True,
        "aeat_send_error": repr(fault)[:60],
        "sii_return": repr(fault),
        "aeat_content_sent": json.dumps(inv_dict, indent=4),
    })
    document.write(doc_vals)
    raise ValidationError(fault) from fault

Everything seems to work well, but this is not the solution I want, since I guess I would lose all the information because of the ROLLBACK. How can I find out why new_cr.commit() loads forever?

3
  • Could be a deadlock, but hard to know by only seeing the code. Where did you find that? I couldn't find it either on the 15.0 nor on the 16.0 branch of that module. Commented Dec 3, 2024 at 12:49
  • Here: github.com/OCA/l10n-spain/blob/16.0/l10n_es_aeat_sii_oca/models/…. Some of the main models inherit from this mixin and thus can call this method. Commented Dec 4, 2024 at 14:28
  • 1
    Okay, i have no idea. What about opening an issue in that repo? Commented Dec 4, 2024 at 15:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.