Openfoodnetwork: Fix error `ActiveModel::UnknownAttributeError: unknown attribute 'distributor' for Spree::Product` on setup

Created on 12 May 2021  Â·  3Comments  Â·  Source: openfoodfoundation/openfoodnetwork

What we should change and why (this is tech debt)

When running setup/script the above error pops up

Context

https://openfoodnetwork.slack.com/archives/C2GQ45KNU/p1620456501144500?thread_ts=1620397593.134200&cid=C2GQ45KNU
Linked issue: #7613

Impact and timeline

Timeline: 1 week. Impact: better onboarding experience for new developers ✨

tech debt

Most helpful comment

they don't error if you have already have the db with seeds on your computer, so that is probably why current devs have not noticed it.

Yep! I think part of the issue is that previous versions of Rails used to silently ignore attributes that were not relevant, but after one of the Rails upgrades the behavior changed to throwing a fatal error instead.

All 3 comments

Aha, I've never seen this before. Yeah it looks like a simple error in that sample data file. We just need to drop the distributor: keys from all the items in this array: https://github.com/openfoodfoundation/openfoodnetwork/blob/99cf23df265ea97a1b6485c08d464da3298670b9/lib/tasks/sample_data/product_factory.rb#L23-L28

I can confirm removing the distributor lines fixed it for me when I tried it yesterday, however I thought these lines were needed, since they were added 2 years ago in commit 2019-01-08 4b389ba357, and touched again in 2020-11-02 5289a5b381

Maybe they were a forgotten part of a bigger change, since no one noticed the error they produced in a while.
Also, they don't error if you have already have the db with seeds on your computer, so that is probably why current devs have not noticed it.

they don't error if you have already have the db with seeds on your computer, so that is probably why current devs have not noticed it.

Yep! I think part of the issue is that previous versions of Rails used to silently ignore attributes that were not relevant, but after one of the Rails upgrades the behavior changed to throwing a fatal error instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipefurtad0 picture filipefurtad0  Â·  3Comments

filipefurtad0 picture filipefurtad0  Â·  3Comments

sauloperez picture sauloperez  Â·  4Comments

Matt-Yorkley picture Matt-Yorkley  Â·  3Comments

kristinalim picture kristinalim  Â·  3Comments