This part of the sqlserver__get_test_sql macro that creates schemas is not concurrency-safe:
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ target.schema }}')
BEGIN
EXEC('CREATE SCHEMA [{{ target.schema }}]')
END
This results in a race condition when the number of threads are more than 1, which often results in the following error:
There is already an object named 'my_schema' in the database.
We have found this to be problematic during CI runs, where a new schema is created for each PR, often resulting in the first CI run failing due to the race condition and us needing to rerun the pipeline again.
This part of the
sqlserver__get_test_sqlmacro that creates schemas is not concurrency-safe:This results in a race condition when the number of threads are more than 1, which often results in the following error:
There is already an object named 'my_schema' in the database.We have found this to be problematic during CI runs, where a new schema is created for each PR, often resulting in the first CI run failing due to the race condition and us needing to rerun the pipeline again.