Sayyiduna Bara bin Azib (may Allah be pleased with him) narrates: Some companions of the Prophet (peace and blessings of Allah be upon him) passed away in such a state that they used to drink alcohol. When alcohol was declared forbidden, some companions of the Prophet (peace and blessings of Allah be upon him) asked: What will happen to our companions who died in such a state that they used to drink alcohol? Then this verse was revealed: "Those who believed and did righteous deeds, there is no sin upon them for what they consumed."
Hadith Referenceصحیح ابن حبان / كتاب الأشربة / 5351
Hadith Gradingفضيلة الشيخ الإمام محمد ناصر الدين الألبانيصحيح لغيره - المصدر نفسه.فضيلة الشيخ العلّامة شُعيب الأرناؤوطإسناده صحيح على شرطهما