Hello everyone,
I am working with Tryton and am trying to raise a user warning in an on_change method when a user updates a specific field. The warning should inform the user if the value entered does not meet certain conditions an invalid format or calculated value). However, when I attempt to raise the warning using raise_user_warning, I encounter an error related to the database transaction (psycopg2 error). Specifically, I get a “cannot execute DELETE in a read-only transaction” error. This error only occurs when I raise the user warning, and I am unsure why it blocks the operation.
I’ve tried using raise_user_error, and the logic works fine, and I also tested using print, which also worked. However, I specifically need to raise a user warning to inform the user of the calculated value and give them the option to continue.
If this approach doesn’t work, could anyone suggest a solution to raise a warning when the user changes the value of a specific field? Any help would be greatly appreciated
You can not raise a warning on read-only transaction.
Indeed on_change
methods can never raise any exception because the flow can not be stopped.
There is no such option with on_change
.
You could use on_change_notify
to display a message but it is just informative.
Or you could raise your warning when the form is saved but it appears later.
Or you can send an asynchronous notification but there is no guarantee that the client will display it.