I'm not sure if a wild animal has ever been observed to have a pet, but I guess many intelligent animals value playfulness and companionship, and have evolved to have tolerance and empathy, so judging by Twitter, etc, it doesn't seem that rare to have inter-species friendships even between animals that might be considered as predator and potential prey.
You don't just rock up to a herd of wild bovines and say "hey, you're my cows now, let me milk you". Rather, one day a group of humans started following a herd around, killing one once in a while for meat; eventually perhaps they started protecting the cattle from other predators and guiding where the herd went, while also starting to find ways to continue lactation in females and get them to acquiesce to being milked.
The cows that were compliant to the slow changes were the most likely to reproduce; rinse and repeat until you get whatever we have now.
There's no peer-reviewed scientific research describing this phenomena. Or even any attempt at gathering any data with something resembling scientific rigor.
A simpler explanation is that these dogs and baboons are just... Living side-by-side in a garbage dump. And that the film-makers just didn't include any footage that didn't fit their narrative.