My Apex Test failed with the following error: Cannot specify both an external ID reference Owner and a salesforce id, OwnerId.
It throws on attempt to Database.update a record. In the debug, I’ve noticed that the record includes data that I don’t specify in a SOQL request: “OwnerId”: “005QL000005HQAFYA4", “Owner”:{“Id”:“005QL000005HQAFYA4”, ...}. I used serialize-deserialize approach to remove the data from the record and the issue disappeared.
I find this behavior odd and would like to learn more about it. My assumption is this is due to the System.runAs that I use upon record creation in Test Setup. Does anyone have an idea why it leads to such behavior? Or is there another reason for that?
P.S.
Here are some explanations on why DML fails with such error in the first place https://salesforce.stackexchange.com/a/423776/70921