(1) Consider easy fix replacing order of
in CUserMacro.php replaceMacros() function
but regarding solution with extra SELECT statement, I think It would be better to make that check inside replaceMacros() function
Error still persist in template edit form, if you remove macro and add macro with same name and then try to save changes.
Alexey Fukalov RESOLVED