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

Download is broken (for at least one experiment) #14

Open
njvack opened this issue Feb 27, 2020 · 3 comments
Open

Download is broken (for at least one experiment) #14

njvack opened this issue Feb 27, 2020 · 3 comments
Assignees

Comments

@njvack
Copy link
Member

njvack commented Feb 27, 2020

I get a 500 error for: /admin/surveys/3.csv on our server

@dgfitch dgfitch self-assigned this Mar 2, 2020
@dgfitch
Copy link
Contributor

dgfitch commented Mar 2, 2020

Can't duplicate this error locally, looking on our server. It's breaking even before it gets to the JSON parser newline error.

I, [2020-03-02T16:47:57.365676 #1612]  INFO -- : [1b9b023c-881a-4113-8bf8-d395b857f7a7]   Rendered admin/surveys/show.csv.erb (14.7ms)
ActionView::Template::Error (PG::SyntaxError: ERROR:  zero-length delimited identifier at or near """"
LINE 1: ...ssages"."survey_id" = $1 ORDER BY "text_messages"."" ASC LIM...
                                                             ^
: SELECT  "text_messages".* FROM "text_messages" WHERE "text_messages"."survey_id" = $1 ORDER BY "text_messages"."" ASC LIMIT $2):

The code in admin/surveys/show.csv.erb looks non-offending:

<%= CSV.generate_line ['survey', 'participant_key', 'from', 'to', 'direction', 'time', 'message'] -%>
<%- @survey.text_messages.order('created_at').find_each do |m| -%>
<%= CSV.generate_line([@survey.name, m.participant_external_key, m.from_number.humanize, m.to_number.humanize, m.direction, m.delivered_at_in_zone, m.message]).html_safe -%>
<%- end -%>

I dunno what about the @survey.text_messages.order call could be making it generate ORDER BY "text_messages".""

Interestingly, if I go into a console and do

s = Survey.find(3)
s.text_messages.order('created_at')

I get a bunch of stuff. But,

s.text_messages.order('created_at').find_each { |m| p m }
Scoped order is ignored, it's forced to be batch order.
Traceback (most recent call last):
        1: from (irb):2
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  zero-length delimited identifier at or near """")
LINE 1: ...ssages"."survey_id" = $1 ORDER BY "text_messages"."" ASC LIM...
                                                             ^
: SELECT  "text_messages".* FROM "text_messages" WHERE "text_messages"."survey_id" = $1 ORDER BY "text_messages"."" ASC LIMIT $2

Ugh, rails paging magic or something? I suspect this breaks on any survey it has to page, and none of my testing/local surveys have enough data for that.

@njvack
Copy link
Member Author

njvack commented Mar 6, 2020

The issue here is that there's an unescaped \n in server_response for one of the text messages, and so when Rails tries to deseralize the json it barfs.

@njvack
Copy link
Member Author

njvack commented Mar 6, 2020

I could just set server_response to {} for all the records

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

No branches or pull requests

2 participants