How to handle exceptions on user registration errors in erpnext?

Hi Community,

I’m getting MySQL error on user registration. Getting MySQL error is not an issue as I have limited the max number of rows can be inserted on ‘tabUser’ MySQL table to 5 Only.

So it results, when ever 6th user is added, it throws an MySQL error
“OperationalError: (1048, “Column ‘id’ cannot be null”).”.

Now I just want to handle this exception but I don’t know the actual .py file where user registeration is processed and inserted in ‘tabUser’ MySQL table. So I want to know the .py file name from where I can implement my logic for this MySQL exception.

If anyone can provide me the .py file name from where I can handle this exception or any other way to show my custom message for this error, It would be really helpful for me.:slightly_smiling_face:

Thanks.

@progShubham,

check the database.py’s sql method

Hi
makarand_b http://discuss.frappe.io/u/makarand_b

Can you provide me some more details in this *sql *method as I’m not
getting any sql query for user registration in ‘tabUser’ MySql Table.
Thanks.

Remove it. you can handle this by adding validation on user’s form.

use hooks for it

e.g. write method using validate hooks

def validate_user_limit(doc, method):
	user_count = frappe.db.get_value("User", {"enabled": 1}, "count(name)")
	if user_count >= 5 and doc.is_new():
		frappe.throw("User limit is exceeded")