The scene has prompted a furious backlash with some people accusing the filmmakers of creating a movie that “encourages food allergy bullying”.
The filmmakers and the studio, Sony Pictures, have apologised following the outcry over the scene in which Mr McGregor’s nephew Thomas is forced to use an EpiPen as a result of the attack.
It comes after the charity group Kids with Food Allergies posted a warning about the scene on social media and said it had written a letter to the filmmakers.
It wrote in a Facebook post: “It is unnecessary for a film to show the characters intentionally attacking another with his food allergen to trigger anaphylaxis.
“Portraying anaphylaxis as a joke can cause some people to have a cavalier attitude about food allergies which can put kids with food allergies at risk.
“We are asking filmmakers to work with us to raise awareness about the seriousness of food allergies, and help us promote positive attitudes and safe environments for kids with food allergies.”
The controversy triggered a mixed reaction and the hashtag #boycottpeterrabbit on social media, with some people describing the scene as “insensitive”, and others as “funny”.
One parent wrote: “@SonyPictures you are deplorable #boycottpeterrabbit My 2 kids have horrible allergies & u make a joke of it. Not seeing this or any of your movies ever. Honestly not even sure what u were thinking making this scene.”
Another wrote: “This is pretty awful. And I don’t have allergies or kids. None needed to see the insensitivity. #boycottpeterrabbit.”
One woman posted an image of her daughter crying in a bed and wrote: “This is what an anaphylactic reaction looks like in a child. This is AFTER epinephrine and Benadryl. It’s NOT a punchline to a joke. #boycottpeterrabbit.”
However, others didn’t understand what the fuss was about.
One person wrote: “I’m allergic to some foods as well, but this is funny. Quit whining about everything. #boycottpeterrabbit #crybabies.”
Another said: “This is officially crazy. I’m going to #boycottpeterrabbit not because of the scene in question, but because they apologised for it. #JustAMoviePeople.”
Kenneth Mendez, the president and CEO of the Asthma and Allergy Foundation of America, also wrote an open letter to the studio urging it to “examine your portrayal of bullying in your films geared toward a young audience”.
The studio and filmmakers said that they “sincerely regret not being more aware and sensitive to this issue, and we truly apologise”.
The controversial scene is in a film adaptation of Peter Rabbit, the much-loved Beatrix Potter character, which was released in US cinemas at the weekend.
The movie, starring James Corden who voices the character of Peter, will hit the big screen in the UK on 16 March.