Recently, I had to add a second“mandatory” flag to DocField: 'Mandatory only in DB'.
The challenge with ‘Mandatory’ is that it enforces mandatory values in both frontend JavaScript, and backend Python.
I wanted to enforce a value in the database. But I didn’t care if the User entered a value on the web page. If they did, I’d accept it. But otherwise, a value is automatically assigned in the Document’s 'before_validate()' function.
Do you really think the dev team would want to include something like this?!?
It seems to be a very specific use case and would require a great deal more knowledge of how to use it than the average user base.
Sometimes you do something for a specific client need and let it work for a while before you consider if it has value to the core system. And sometimes the hurdles to jump for a PR are just not available in your calendar.
Just my opinion… (and you know what they say about opinions).
Instead, I was thinking about all the tremendous value invested in tweaks to core software that never make it into the code base and. possibly, get reinvented dozens of times.
IMO, you should file an issue or even add a PR for this.
This is NOT a rare edge case.
Requiring a value, but if none is given, trying to default to something else, otherwise throw a validation error – this strategy is used in several Frappe and ERPNext core doctypes, so even Core would profit from a “Mandatory only in DB“ feature.