sendgrid / eventkit-rails

An open source project for integrating with SendGrid's Event Webhook.
Open Software License 3.0
53 stars 73 forks source link

Event API fails to search on type_id #29

Open bardbess opened 7 years ago

bardbess commented 7 years ago

When doing a search from ember on the type column I'm getting the following exception.

App 14766 stdout: Processing by Api::V1::EventsController#index as JSON
App 14766 stdout:   Parameters: {"descending"=>"1", "detailed"=>"{\"type\":[\"\\\"bounced\\\"\"]}", "like"=>"true", "limit"=>"10", "offset"=>"0", "sortby"=>"timestamp"}
App 14766 stdout: PG::UndefinedColumn: ERROR:  column "type" does not exist
App 14766 stdout: LINE 1: SELECT COUNT(*) FROM "events"  WHERE ("type" LIKE '%"bounced...
App 14766 stdout:                                               ^
App 14766 stdout: : SELECT COUNT(*) FROM "events"  WHERE ("type" LIKE '%"bounced"%')
App 14766 stdout: Completed 500 Internal Server Error in 2ms
App 14766 stdout: 
App 14766 stdout: ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column "type" does not exist
App 14766 stdout: LINE 1: SELECT COUNT(*) FROM "events"  WHERE ("type" LIKE '%"bounced...
App 14766 stdout:                                               ^
App 14766 stdout: : SELECT COUNT(*) FROM "events"  WHERE ("type" LIKE '%"bounced"%')):
App 14766 stdout:   app/controllers/api/v1/events_controller.rb:61:in `index'

The request is searching on the type column rather than the type_id column.

I can see there is a conditions in the receiver for renaming this key when coming back from sendgrid. Looks like the events_controller can be safely corrected to accept type_id