Unique validator not firing with audit columns (populated using behaviors)

I have setup a unique constraints such as below

[['pname', 'created_by'], 'unique', 'targetAttribute' => ['pname', 'created_by'], 'message' => 'Project Name already in use'],

However, when the condition is met, instead of throwing an error message I get Database error - basically the validation is not firing. The debug logs show this SQL being executed to validate:

SELECT EXISTS(SELECT * FROM sometable WHERE (pname='New Project') AND (created_by IS NULL))

I suppose the explanation here is that the behaviors (to populate created_by) kicks in after the validation, hence this exception is not handled gracefully. FYI, the created_by has a numeric value in the insert. Anyone else has thoughts or workarounds?

So, the uniqueness of the project name is per user, i.e., the project name can be the same when the created_by is different, right?
Then I think you have to populate created_by manually before validation.

Thanks @softark. Confirmed that populating manually is indeed the way to resolve this.