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

AudioEvents filter failing with malformed SQL #305

Closed
2 tasks done
atruskie opened this issue Nov 7, 2016 · 1 comment
Closed
2 tasks done

AudioEvents filter failing with malformed SQL #305

atruskie opened this issue Nov 7, 2016 · 1 comment
Assignees
Labels

Comments

@atruskie
Copy link
Member

atruskie commented Nov 7, 2016

An ActiveRecord::StatementInvalid occurred in audio_events#filter:

PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type numeric: "---
:from: 0 :to: " LINE 1: …time_seconds" – “audio_events"."start_time_seconds”) >= '---

^
: SELECT COUNT(*) FROM “audio_events” INNER JOIN “audio_recordings” ON “audio_recordings"."id” = “audio_events"."audio_recording_id” AND ("audio_recordings"."deleted_at" IS NULL) INNER JOIN “sites” ON “sites"."id” = “audio_recordings"."site_id” AND ("sites"."deleted_at" IS NULL) WHERE ("audio_events"."deleted_at" IS NULL) AND (EXISTS (SELECT 1 FROM “projects_sites” WHERE “sites"."id” = “projects_sites"."site_id” AND EXISTS (( SELECT 1 FROM “projects” WHERE “projects"."deleted_at” IS NULL AND “projects"."creator_id” = 234 AND “projects_sites"."project_id” = “projects"."id” UNION ALL SELECT 1 FROM “permissions” WHERE “permissions"."user_id” = 234 AND “permissions"."level” IN ('reader', ‘writer’, ‘owner’) AND “projects_sites"."project_id” = “permissions"."project_id” ))) OR EXISTS (SELECT 1 FROM “audio_events” “ae_ref” WHERE “ae_ref"."deleted_at” IS NULL AND “ae_ref"."is_reference” = ‘t’ AND “ae_ref"."id” = “audio_events"."id")) AND “audio_events"."is_reference” = ‘t’ AND (("audio_events"."end_time_seconds” – “audio_events"."start_time_seconds”) >= '--- :from: 0 :to: ') AND ("audio_events"."low_frequency_hertz" >= 1100)

lib/modules/api/response.rb:272:in `add_paging_and_sorting'

The request came from the reference library:

------------------------------- Request:

* URL        : https://www.ecosounds.org/audio_events/filter
* HTTP Method: POST
* Parameters : {"filter"=>{"isReference"=>{"eq"=>true}, "durationSeconds"=>{"gteq"=>{"from"=>0, "to"=>nil}}, "lowFrequencyHertz"=>{"gteq"=>1100}}, "paging"=>{"items"=>10, "page"=>1}, "format"=>"json", "controller"=>"audio_events", "action"=>"filter", "audio_event"=>{}}
* HTTP_REFERER                                   : https://www.ecosounds.org/library?reference=reference&minDuration=0&lowFrequency=1100&page=1&items=10

It looks like some custom SQL condition seems to be malformed, the '--- :from: 0 :to: '. That was probably drawn from the "durationSeconds"=>{"gteq"=>{"from"=>0, "to"=>nil}} block in the params - which is a malformed filter from the client.

Action item

  • Better validate the filter queries for this particular case
  • When done, file issue in client to stop malformed filter requests
@atruskie
Copy link
Member Author

atruskie commented Dec 4, 2016

Client issue: QutEcoacoustics/baw-client#284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants