Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError in AmendBackorderJob@default #13056

Open
mkllnk opened this issue Jan 2, 2025 · 2 comments · May be fixed by #13065
Open

NoMethodError in AmendBackorderJob@default #13056

mkllnk opened this issue Jan 2, 2025 · 2 comments · May be fixed by #13065
Assignees
Labels

Comments

@mkllnk
Copy link
Member

mkllnk commented Jan 2, 2025

Error in Open Food Network (Rails)

NoMethodError in AmendBackorderJob@default
undefined method `lines' for nil:NilClass

order.lines.find do |line|
     ^^^^^^

View on Bugsnag

Stacktrace

app/services/fdc_backorderer.rb:111 - find_order_line
app/services/fdc_backorderer.rb:90 - find_or_build_order_line
app/services/backorder_updater.rb:60 - block in update_order_lines
app/services/backorder_updater.rb:57 - map
app/services/backorder_updater.rb:57 - update_order_lines
app/services/backorder_updater.rb:45 - update
app/services/backorder_updater.rb:31 - amend_backorder
app/jobs/amend_backorder_job.rb:24 - amend_backorder
app/jobs/amend_backorder_job.rb:19 - block in perform
app/services/order_locker.rb:18 - block in lock_order_and_variants
app/services/order_locker.rb:16 - lock_order_and_variants
app/jobs/amend_backorder_job.rb:18 - perform

View full stacktrace

Created by Maikel via Bugsnag

@mkllnk
Copy link
Member Author

mkllnk commented Jan 3, 2025

AmendBackorderJobs are failing because there is no backorder to amend. The jobs started failing after the order cycle closed. At that point, the backorder is finalised and not available for amendments any more.

Technically, I can just add a guard-clause to not try amend a missing backorder. But let's go through some scenarios to see if it's the right fit, thinking out loud.

  • The order cycle is complete and an admin is adjusting orders. This is totally valid and therefore we added a delay for one of the enterprises. Ideally, this could be configured by the enterprise. So if the enterprise has finalised the backorder already then we shouldn't do anything. Manual tweaks are allowed without triggering more logic. Also, if orders are cancelled, we are not able to place an order with negative quantities at this point.
  • The order cycle is open and an admin is creating the first order. There is no backorder to amend yet. We could create a new backorder instead of trying to amend an existing one. This is a valid use case.
  • The order cycle closed and the admin creates a new order. We could place a new backorder but after creation we wouldn't know which orders were already accounted for in a previous backorder or not. We currently associate a backorder only to the order cycle and not to each individual order. Supporting this would be a lot of work because it doesn't fit into the current model.

So I would propose:

  • When we try to amend a backorder and there is none then we check if the order cycle is open. Only if it's open then we can place a new order.

@mkllnk mkllnk self-assigned this Jan 3, 2025
@mkllnk mkllnk moved this from All the things 💤 to In Progress ⚙ in OFN Delivery board Jan 3, 2025
@RaggedStaff
Copy link
Collaborator

That makes sense to me. We will need to think about the final point (linking OFN Orders to DFC Orders) in the future, but I agree it's out of scope for now.

We prob need a warning (on the import screen? ) about back order finalisation. Could have the delay finalise by X time there too. I'll add that to the wishlist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress ⚙
Development

Successfully merging a pull request may close this issue.

2 participants