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

bug(filterApi) Projection filter options being ignored #170

Closed
atruskie opened this issue Mar 10, 2015 · 3 comments
Closed

bug(filterApi) Projection filter options being ignored #170

atruskie opened this issue Mar 10, 2015 · 3 comments

Comments

@atruskie
Copy link
Member

POST staging.ecosounds.org/audio_recordings/filter
with body of:

{
  "projection": {
    "include": ["id"] 
  }
}

Returns data items like this (full entities):

{
"status": "ready",
"id": 239600,
"site_id": 895,
"uuid": "176782d0-0b85-4af9-a7ce-be10f5fcd5f4",
"uploader_id": 120,
"recorded_date": "2013-09-17T09:19:24.000+10:00",
"duration_seconds": 6801.92,
"sample_rate_hertz": 16000,
"channels": 2,
"bit_rate_bps": 512000,
"media_type": "audio/x-wav",
"data_length_bytes": 435323392,
"file_hash": "SHA256::4ffabdb48eca9f567bccc55b46d54a230f4e107248dcf5cd9f0299dd7d7184be",
"notes": "\"UploadStartUTC\"=\"26/11/2013 12:16:44 AM\"\r\n\"site_id\"=\"895\"\r\n\"site_name\"=\"Emerald River 1\"\r\n\"site_createdby\"=\"88f8a51a-c4ea-4ce3-abe6-0b331921b8a5\"\r\n\"site_createdby_name\"=\"wimmerj\"\r\n\"site_type\"=\"2\"\r\n\"site_notes\"=\"\\\"Start\\\"\"\r\n\"site_createddate\"=\"2013-11-26T10:14:54.167+10:00\"\r\n\"dep_entity_id\"=\"897\"\r\n\"dep_entity_name\"=\"emeraldcreek_Emerald Creek244\"\r\n\"dep_entity_createdby\"=\"a8e5237d-d356-4edd-8e81-0f9770c1ce5d\"\r\n\"dep_entity_createdby_name\"=\"upload\"\r\n\"dep_entity_type\"=\"4\"\r\n\"dep_entity_notes\"=\"\\\"Deployment created the first time audio was uploaded to a sensor in a site.\\\"\"\r\n\"dep_entity_depid\"=\"025f5f32-148b-42d6-80a9-47f291d37cf2\"\r\n\"dep_entity_createddate\"=\"2013-11-26T10:15:42.550+10:00\"\r\n\"dep_id\"=\"025f5f32-148b-42d6-80a9-47f291d37cf2\"\r\n\"dep_hardwareid\"=\"211\"\r\n\"dep_name\"=\"emeraldcreek_Emerald Creek244\"\r\n\"dep_datestarted\"=\"2013-11-26T00:15:42.153+10:00\"\r\n\"dep_istest\"=\"False\"\r\n\"dep_createdby\"=\"a8e5237d-d356-4edd-8e81-0f9770c1ce5d\"\r\n\"dep_createdby_name\"=\"upload\"\r\n\"dep_createdtime\"=\"2013-11-26T10:15:42.337+10:00\"\r\n\"dep_isactive\"=\"False\"\r\n\"dep_timeout\"=\"0\"\r\n\"hardware_id\"=\"211\"\r\n\"hardware_uniqueid\"=\"125808b3-a127-4d91-9fb0-c5a39d32e712\"\r\n\"hardware_friendly\"=\"emeraldcreek\"\r\n\"hardware_manual\"=\"True\"\r\n\"hardware_createdby\"=\"a8e5237d-d356-4edd-8e81-0f9770c1ce5d\"\r\n\"hardware_createdby_name\"=\"upload\"\r\n\"hardware_createdtime\"=\"2013-11-26T10:15:42.043+10:00\"\r\n\"hardware_lastcontacted\"=\"2013-11-26T10:15:42.043+10:00\"",
"creator_id": 120,
"updater_id": 120,
"deleter_id": null,
"created_at": "2013-11-26T10:16:43.000+10:00",
"updated_at": "2013-11-26T10:16:43.000+10:00",
"deleted_at": null,
"original_file_name": "GROOTE7177_20130917_091924.wav",
"recorded_utc_offset": null
},

This bug is currently is only on staging - it appears to be a regression not caught by tests.

@atruskie
Copy link
Member Author

Also, weirdly, this seems to have changed the order of the resulting data :-/

@cofiem
Copy link
Contributor

cofiem commented Mar 10, 2015

This one is just ridiculously weird. The SQL is all fine, but when it's rendered the model instances are completely different. I do need to add tests to ensure fields not in the projection are properly included/excluded.

I had a quick look, but I really have no idea just now.

Note to self: make tests for more than just query_full.

cofiem pushed a commit that referenced this issue Mar 11, 2015
cofiem pushed a commit that referenced this issue Mar 13, 2015
Added checks for filter endpoint returning unwanted attributes #170
@cofiem
Copy link
Contributor

cofiem commented Mar 14, 2015

I think I've figured this out. Using .includes and .joins results in much more understandable and easy queries, but it also adds all the attributes of each model to the select list. This is very difficult to change. e.g. here

Suggested alternative is to control the rendering to json rather than trying to modify how rails does the query. Controlling the json rendering is more supported and easier to change.

e.g. have another look at jbuilder (which is added by default with Rails 4)

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

No branches or pull requests

2 participants