Unique constraint on one column, upsert lookup on two
@alandev03▲ -2 net votes
source_key is UNIQUE, but the code looks up (source_key, source_type). The same key with a new type fails the lookup, then the insert fails with IntegrityError (500). Make the lookup match the constraint, and handle IntegrityError for concurrent first-inserts.