Every dbt test creates a view with the name "testview_". If a test can not be executed, maybe because a column name is wrong, the view doesn't get dropped afterwards.
The next iteration might want to create a view with the same name, because the range of the random funtion is quite limited. It can't create that, because the name is already taken (if you are unlucky). This leads to an error.
Solution
Instead of using a random function, I used testview_{{ local_md5(model.name ~ invocation_id) }}. Not using MD5 would be nicer for readability, but you might run into issues regarding the maximum object name length of 128 characters.
Problem
Every dbt test creates a view with the name "testview_". If a test can not be executed, maybe because a column name is wrong, the view doesn't get dropped afterwards.
The next iteration might want to create a view with the same name, because the range of the random funtion is quite limited. It can't create that, because the name is already taken (if you are unlucky). This leads to an error.
Solution
Instead of using a random function, I used
testview_{{ local_md5(model.name ~ invocation_id) }}
. Not using MD5 would be nicer for readability, but you might run into issues regarding the maximum object name length of 128 characters.