#28 SQL issue reading comment
Closed: Fixed Opened by trasher.

For one of my tests, I've copy/paste a full markdown example in a comment (http://www.unexpected-vortices.com/sw/rippledoc/quick-markdown-example.html); and I get the following SQL error when displayiung the comment:

[Sun Oct 12 10:36:08.744145 2014] [:error] [pid 26937] [client 176.181.157.150:39843] Traceback (most recent call last):, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744164 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744542 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     return self.wsgi_app(environ, start_response), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744559 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744579 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     response = self.make_response(self.handle_exception(e)), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744590 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744604 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     reraise(exc_type, exc_value, tb), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744614 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744660 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     response = self.full_dispatch_request(), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744673 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744689 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     rv = self.handle_user_exception(e), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744700 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744715 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     reraise(exc_type, exc_value, tb), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744725 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744739 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     rv = self.dispatch_request(), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744750 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744764 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     return self.view_functions[rule.endpoint](**req.view_args), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744775 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/var/www/python_apps/ProGit/progit/ui/issues.py", line 165, in view_issue, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744851 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     issue = progit.lib.get_issue(SESSION, repo.id, issueid), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.744866 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/var/www/python_apps/ProGit/progit/lib.py", line 592, in get_issue, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745050 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     return query.first(), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745067 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2295, in first, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745583 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     ret = list(self[0:1]), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745599 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2162, in __getitem__, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745617 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     return list(res), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745626 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2366, in __iter__, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745640 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     return self._execute_and_instances(context), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745651 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/orm/query.py", line 2381, in _execute_and_instances, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745676 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     result = conn.execute(querycontext.statement, self._params), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.745691 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 662, in execute, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746027 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     params), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746044 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 761, in _execute_clauseelement, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746063 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     compiled_sql, distilled_params, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746074 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 874, in _execute_context, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746089 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     context), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746100 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746115 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     exc_info, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746125 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.py", line 196, in raise_from_cause, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746190 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     reraise(type(exception), exception, tb=exc_tb), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746205 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 867, in _execute_context, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746222 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     context), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746232 2014] [:error] [pid 26937] [client 176.181.157.150:39843]   File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 324, in do_execute, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746401 2014] [:error] [pid 26937] [client 176.181.157.150:39843]     cursor.execute(statement, parameters), referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746451 2014] [:error] [pid 26937] [client 176.181.157.150:39843] DataError: (DataError) ERREUR:  syntaxe en entr\xc3\xa9e invalide pour l'entier : \xc2\xab example-image.jpg \xc2\xbb, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746460 2014] [:error] [pid 26937] [client 176.181.157.150:39843] LINE 4: ...non_1.issue_id = issues.id AND anon_1.global_id = 'example-i..., referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746464 2014] [:error] [pid 26937] [client 176.181.157.150:39843]                                                              ^, referer: http://progit.ulysses.fr/PR%20Test/issue/2
[Sun Oct 12 10:36:08.746467 2014] [:error] [pid 26937] [client 176.181.157.150:39843]  'SELECT issues.id AS issues_id, issues.uid AS issues_uid, issues.project_id AS issues_project_id, issues.title AS issues_title, issues.content AS issues_content, issues.user_id AS issues_user_id, issues.status AS issues_status, issues.date_created AS issues_date_created \\nFROM issues, (SELECT global_id.id AS id, global_id.project_id AS project_id, global_id.issue_id AS issue_id, global_id.request_id AS request_id, row_number() OVER (PARTITION BY global_id.project_id ORDER BY global_id.id) AS global_id \\nFROM global_id) AS anon_1 \\nWHERE issues.project_id = %(project_id_1)s AND issues.project_id = %(project_id_2)s AND anon_1.project_id = issues.project_id AND anon_1.issue_id = issues.id AND anon_1.global_id = %(global_id_1)s ORDER BY issues.id \\n LIMIT %(param_1)s' {'project_id_1': 7, 'project_id_2': 7, 'global_id_1': u'example-image.jpg', 'param_1': 1}, referer: http://progit.ulysses.fr/PR%20Test/issue/2

ERREUR: syntaxe en entr\xc3\xa9e invalide pour l'entier

The problem is that the markdown includes a link to "example-image.jpg" so progit tries to load /progit/issue/example-image.jpg which of course does not exist and this leads to that exception.

We can fix it at two levels:
* in flask by requiring an integer to be specified in the URL
* in the application by catching the SQLAlchemy exception

After testing the first approach seems the best: let flask enforce the provided issue_id to be an integer

Fixed in http://209.132.184.222/progit/32cbdc4bbbc634dca15846476c2e58a08905efeb and display in http://209.132.184.222/progit/cbb77da3d7c44045c325ab3213223bcb61a47e40

ERREUR: syntaxe en entr\xc3\xa9e invalide pour l'entier

The problem is that the markdown includes a link to "example-image.jpg" so progit tries to load /progit/issue/example-image.jpg which of course does not exist and this leads to that exception.

We can fix it at two levels:
* in flask by requiring an integer to be specified in the URL
* in the application by catching the SQLAlchemy exception

After testing the first approach seems the best: let flask enforce the provided issue_id to be an integer

Fixed in http://209.132.184.222/progit/32cbdc4bbbc634dca15846476c2e58a08905efeb and display in http://209.132.184.222/progit/cbb77da3d7c44045c325ab3213223bcb61a47e40

Metadata