foodcoops / foodsoft

Web-based software to manage a non-profit food coop (product catalog, ordering, accounting, job scheduling).
https://foodcoops.net/
Other
318 stars 146 forks source link

Synchronize from external database fails with "out of range" error #1030

Open kidhab opened 9 months ago

kidhab commented 9 months ago

A foodcoop at app.foodcoops.net tries to synchronize articles from the external (Sharedlists) database. It fails for one supplier with the following error message:

An ActiveModel::RangeError occurred in articles#update_synchronized:

  6000000000 is out of range for ActiveModel::Type::Integer with limit 4 bytes
  app/controllers/articles_controller.rb:194:in `block (2 levels) in update_synchronized'

Looking at the parameters from this request it shows entries like this one:

"388"=>{"name"=>"cranberry siroop", "shared_updated_on"=>"", "note"=>"Biologisch", "manufacturer"=>"TERSCHELLINGER", "origin"=>"NL", "unit"=>"500ml", "unit_quantity"=>"6000000000.0", "price"=>"0.0", "tax"=>"9.0", "deposit"=>"0.0", "article_category_id"=>"5"}

There are others entries which have unit_quantity"=>"6000000000.0

The XML file from the supplier lists the unit_quantity as <sve>6</sve> which is then saved to the Sharedlists database as 6.0.

Any idea why this error happened?

yksflip commented 9 months ago

I have almost no insights into sharedlist yet, but maybe I can help debugging by digging into it a bit ...

So the unit_quantity is stored correctly in the sharedlists db, right? So I guess the bug is somewhere on the foodsoft side synchronizing the articles.

Because in the request params is already the wrong unit_quantity, I guess that the bug must be somewhere before update_synchronized is called. Was the unit_quantity correct in the sync form view? I think that must be the screen that shows the differences of the updated articles ... I'd guess that it's already wrong here?

can you maybe also provide the article details before syncing?

yksflip commented 9 months ago

I think this could happen when the foodcoop article unit is much smaller than the shared_list unit? e.g.

article.update!(unit: '0.1ml', unit_quantity: 1)
shared_article.update!(unit: '100ml', unit_quantity: 1.0)
updated_article = supplier.sync_all[0].select { |s| s[0].id == article.id }.first[0]
article.update(updated_article.attributes.reject { |k, _v| %w[id type].include?(k) })

will give the same out of range error when calling article.update

hamaryns commented 3 months ago

Any progress on this? We still can’t synchronize our prices…

yksflip commented 3 months ago

thanks for pinging again! My messy mind completely forgot about it, sorry! I already managed to reproduce the error in ab1fc34 I'll look into it again!