Make data binding errors warnings

We use data bindings extensively (love 'em).

However we do find they contribute to bugs, and sometimes these bugs can be hard to catch. We got caught out today when the following (bound to a label text property) failed:

f"$ {self.item_row['cost']:.2f}"}

In this case self.item_row['cost'] was unexpectedly None. So the binding failed and everything died terribly (well, the form never loaded). We dealt with the conditional and all is well again.

Okay, yes, we should have anticipated it could be None, or should have prevented that from ever happening. Still though, the fact that this causes an error that basically kills the page feels disproportionate. Is it possible we could treat this as we would when an event_handler is specified but doesn’t exist, i.e. as a warning? At least for apps in production and without write-back… Returning ‘None’ (or the default value?) feels appropriate in most cases… If write-back IS on, then returning None would cause an exception only when the value is changed (when the value tries to be set) vs preventing the page from loading…

I tried to handle this with set_default_error_handling but there was no way I could find to identify binding (vs other) exceptions.

Current behavior: On an exception in a data binding, an exception is raised.
Suggested behavior: On an exception in a data binding, a warning is raised and the default value is returned.

2 Likes

Note that f-strings, e.g.,

are not data bindings, but a built-in feature of Python. But I take it, this was used inside a data-binding expression, in the IDE.

How about an event-handler for data-binding errors? Then you could customize the behavior as you see fit. On a page that has both serious and not-so-serious errors, you could identify and handle each case appropriately.

Thanks, I made a small change to make that more clear - you are correct that that failed inside a binding.

Errors in databinding used to kill the form as you say without giving any information.

Then, for a short period, they used to show a beautiful traceback with a link that would open the form in design mode and set the focus to the offending databinding. If more than one databinding failed, there was one traceback per failed databinding.

Then the link stopped working.
Then the tracebacks stopped appearing.

I loved them and enjoyed them while they were working. I haven’t checked recently, but last time I had a databinding problem they were still broken.

Se here: [Beta] Clicking on link on traceback error from databinding doesn't work