sleede/fab-manager

(Bug) column slots_reservations.canceled_at does not exist

Guichaguri opened this issue · 1 comments

Describe the bug
The error: column slots_reservations.canceled_at does not exist is thrown whenever the user tries to list slots from a machine.

I believe the error is caused by this line:

.where('slots_reservations.canceled_at': nil)

The slots_reservations table does not have a canceled_at column, only the slots table does.

To Reproduce
Steps to reproduce the behavior:

  1. Click to reserve a machine
  2. There are no slots in the calendar, and the /api/availabilities/machines/... returned an 500 error.
  3. Open the log file
  4. See error

Expected behavior
The registered slots show up as expected and no error is thrown.

Server (please complete the following information):

  • Fab-manager version 5.4.13

Browser (please complete the following information):

  • Name: Chrome
  • Version: 104.0.5112.101

Additional context
Full Error Log

Started GET "/api/availabilities/machines/cortadora-laser?start=2022-08-22T00%3A00%3A00&end=2022-08-29T00%3A00%3A00&timezone=America%2FSao_Paulo&_=1660926850078" for 187.72.140.154 at 2022-08-19 17:03:20 +0000
Processing by API::AvailabilitiesController#machine as JSON
  Parameters: {"start"=>"2022-08-22T00:00:00", "end"=>"2022-08-29T00:00:00", "timezone"=>"America/Sao_Paulo", "_"=>"1660926850078", "machine_id"=>"cortadora-laser"}
  �[1m�[36mUser Load (0.3ms)�[0m  �[1m�[34mSELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2�[0m  [["id", 4197], ["LIMIT", 1]]
  �[1m�[36mSetting Load (0.4ms)�[0m  �[1m�[34mSELECT  "settings".* FROM "settings" WHERE "settings"."name" = $1 LIMIT $2�[0m  [["name", "confirmation_required"], ["LIMIT", 1]]
  �[1m�[36mHistoryValue Load (0.3ms)�[0m  �[1m�[34mSELECT  "history_values".* FROM "history_values" WHERE "history_values"."setting_id" = $1 ORDER BY "history_values"."created_at" DESC LIMIT $2�[0m  [["setting_id", 51], ["LIMIT", 1]]
  �[1m�[36mRole Load (17.2ms)�[0m  �[1m�[34mSELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))�[0m  [["user_id", 4197]]
  �[1m�[36mSetting Load (19.5ms)�[0m  �[1m�[34mSELECT  "settings".* FROM "settings" WHERE "settings"."name" = $1 LIMIT $2�[0m  [["name", "visibility_yearly"], ["LIMIT", 1]]
  �[1m�[36mHistoryValue Load (0.3ms)�[0m  �[1m�[34mSELECT  "history_values".* FROM "history_values" WHERE "history_values"."setting_id" = $1 ORDER BY "history_values"."created_at" DESC LIMIT $2�[0m  [["setting_id", 30], ["LIMIT", 1]]
  �[1m�[36mSetting Load (0.2ms)�[0m  �[1m�[34mSELECT  "settings".* FROM "settings" WHERE "settings"."name" = $1 LIMIT $2�[0m  [["name", "visibility_others"], ["LIMIT", 1]]
  �[1m�[36mHistoryValue Load (0.3ms)�[0m  �[1m�[34mSELECT  "history_values".* FROM "history_values" WHERE "history_values"."setting_id" = $1 ORDER BY "history_values"."created_at" DESC LIMIT $2�[0m  [["setting_id", 31], ["LIMIT", 1]]
  �[1m�[36mCACHE Role Load (0.0ms)�[0m  �[1m�[34mSELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))�[0m  [["user_id", 4197]]
  �[1m�[36mMachine Load (0.4ms)�[0m  �[1m�[34mSELECT  "machines".* FROM "machines" WHERE "machines"."slug" = $1 ORDER BY "machines"."id" ASC LIMIT $2�[0m  [["slug", "cortadora-laser"], ["LIMIT", 1]]
  �[1m�[36mCACHE Role Load (0.0ms)�[0m  �[1m�[34mSELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))�[0m  [["user_id", 4197]]
  �[1m�[35mSQL (41.2ms)�[0m  �[1m�[34mSELECT "availabilities"."id" AS t0_r0, "availabilities"."start_at" AS t0_r1, "availabilities"."end_at" AS t0_r2, "availabilities"."available_type" AS t0_r3, "availabilities"."created_at" AS t0_r4, "availabilities"."updated_at" AS t0_r5, "availabilities"."nb_total_places" AS t0_r6, "availabilities"."destroying" AS t0_r7, "availabilities"."lock" AS t0_r8, "availabilities"."is_recurrent" AS t0_r9, "availabilities"."occurrence_id" AS t0_r10, "availabilities"."period" AS t0_r11, "availabilities"."nb_periods" AS t0_r12, "availabilities"."end_date" AS t0_r13, "availabilities"."slot_duration" AS t0_r14, "machines_availabilities"."id" AS t1_r0, "machines_availabilities"."machine_id" AS t1_r1, "machines_availabilities"."availability_id" AS t1_r2, "tags"."id" AS t2_r0, "tags"."name" AS t2_r1, "tags"."created_at" AS t2_r2, "tags"."updated_at" AS t2_r3, "plans"."id" AS t3_r0, "plans"."name" AS t3_r1, "plans"."amount" AS t3_r2, "plans"."interval" AS t3_r3, "plans"."group_id" AS t3_r4, "plans"."stp_plan_id" AS t3_r5, "plans"."created_at" AS t3_r6, "plans"."updated_at" AS t3_r7, "plans"."training_credit_nb" AS t3_r8, "plans"."is_rolling" AS t3_r9, "plans"."description" AS t3_r10, "plans"."type" AS t3_r11, "plans"."base_name" AS t3_r12, "plans"."ui_weight" AS t3_r13, "plans"."interval_count" AS t3_r14, "plans"."slug" AS t3_r15, "plans"."disabled" AS t3_r16, "plans"."monthly_payment" AS t3_r17, "plans"."plan_category_id" AS t3_r18, "slots"."id" AS t4_r0, "slots"."start_at" AS t4_r1, "slots"."end_at" AS t4_r2, "slots"."created_at" AS t4_r3, "slots"."updated_at" AS t4_r4, "slots"."availability_id" AS t4_r5, "slots"."ex_start_at" AS t4_r6, "slots"."ex_end_at" AS t4_r7, "slots"."canceled_at" AS t4_r8, "slots"."offered" AS t4_r9, "slots"."destroying" AS t4_r10 FROM "availabilities" INNER JOIN "slots" ON "slots"."availability_id" = "availabilities"."id" LEFT OUTER JOIN "machines_availabilities" ON "machines_availabilities"."availability_id" = "availabilities"."id" LEFT OUTER JOIN "availability_tags" ON "availability_tags"."availability_id" = "availabilities"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "availability_tags"."tag_id" LEFT OUTER JOIN "plans_availabilities" ON "plans_availabilities"."availability_id" = "availabilities"."id" LEFT OUTER JOIN "plans" ON "plans"."id" = "plans_availabilities"."plan_id" WHERE "machines_availabilities"."machine_id" = $1 AND (availabilities.start_at <= '2022-08-30 02:59:59.999999' AND availabilities.end_at >= '2022-08-22 03:00:00' AND available_type = 'machines') AND (slots.start_at > '2022-08-22 03:00:00' AND slots.end_at < '2022-08-30 02:59:59.999999') AND "availabilities"."lock" = $2�[0m  [["machine_id", 6], ["lock", false]]
  �[1m�[36mMachine Load (0.6ms)�[0m  �[1m�[34mSELECT "machines".* FROM "machines" INNER JOIN "machines_availabilities" ON "machines"."id" = "machines_availabilities"."machine_id" WHERE "machines_availabilities"."availability_id" = $1�[0m  [["availability_id", 137]]
  �[1m�[36mStatisticProfile Load (0.3ms)�[0m  �[1m�[34mSELECT  "statistic_profiles".* FROM "statistic_profiles" WHERE "statistic_profiles"."user_id" = $1 LIMIT $2�[0m  [["user_id", 4197], ["LIMIT", 1]]
  �[1m�[36mSlotsReservation Exists (0.8ms)�[0m  �[1m�[34mSELECT  1 AS one FROM "slots_reservations" LEFT OUTER JOIN "reservations" ON "reservations"."id" = "slots_reservations"."reservation_id" WHERE "slots_reservations"."slot_id" = $1 AND "reservations"."reservable_type" = $2 AND "reservations"."reservable_id" = $3 AND "slots_reservations"."canceled_at" IS NULL LIMIT $4�[0m  [["slot_id", 78], ["reservable_type", "Machine"], ["reservable_id", 6], ["LIMIT", 1]]
Completed 500 Internal Server Error in 389ms (ActiveRecord: 81.6ms | Elasticsearch: 0.0ms)
  
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column slots_reservations.canceled_at does not exist
LINE 1: ... = $2 AND "reservations"."reservable_id" = $3 AND "slots_res...
                                                             ^
: SELECT  1 AS one FROM "slots_reservations" LEFT OUTER JOIN "reservations" ON "reservations"."id" = "slots_reservations"."reservation_id" WHERE "slots_reservations"."slot_id" = $1 AND "reservations"."reservable_type" = $2 AND "reservations"."reservable_id" = $3 AND "slots_reservations"."canceled_at" IS NULL LIMIT $4):
  
app/services/availabilities/status_service.rb:27:in `slot_reserved_status'
app/services/availabilities/availabilities_service.rb:23:in `block in machines'
app/services/availabilities/availabilities_service.rb:23:in `map'
app/services/availabilities/availabilities_service.rb:23:in `machines'
app/controllers/api/availabilities_controller.rb:76:in `machine'
app/controllers/application_controller.rb:70:in `switch_locale'

I figured out the cause of this issue was because migrations have not been executed properly.