It seems I found another bug:
I created a client with admin account then 1 website with 1 user I assigned the user to admin for the site. I set max domains to 1 so the user could not create second domain (actually that would work forreseller correct me if I'm wrog but the logic is the same. If I neet a user to have 1 domain I write 1)
Now the bug happens when you trie to add additional apache directives you get error like I said before, the ispconfig changes the max domain to 2 and you can save the site profile.
I consider this a bug if ispconfig needs to have max 2 to host 1 site I should not be able to create the site from start. Now I discoved this when tried to add additional apache directives.
BTW your code was right it worked i have no more 500 errors.