Project

Profile

Help

Issue #1485

TemplateDoesNotExist exception for '500.html' raised on v3 API endpoint

Added by lastmikoi almost 5 years ago. Updated over 1 year ago.

Status:
CLOSED - WONTFIX
Priority:
High
Assignee:
-
Start date:
Due date:
Estimated time:
Severity:
3. High
Version:
2.7.1
Platform Release:
OS:
CentOS 6
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:

Description

I'm trying to set up my project's librarian-puppet to make use the of v3 API, however it seems to be unable to fetch any module because of the fact that pulp_puppet returns a 500 error on the /v3/modules/{module_name} endpoint.

More strangely, it would seems that I'm not able to access the original exception, as a TemplateDoesNotExist exception is raised when django tries to find a template for the 500 error:

curl "repository:repo1@localhost/v3/modules/puppetlabs-apt"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
 root@localhost and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at localhost Port 80</address>
</body></html>
==> /var/log/httpd/error_log <==
[Thu Jan 07 09:10:12 2016] [error] [client ::1] mod_wsgi (pid=20343): Exception occurred processing WSGI script '/srv/pulp/puppet_forge.wsgi'.
[Thu Jan 07 09:10:12 2016] [error] [client ::1] Traceback (most recent call last):
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     response = self.get_response(request)
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 151, in get_response
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 226, in handle_uncaught_exception
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     return callback(request, **param_dict)
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     response = view_func(request, *args, **kwargs)
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/views/defaults.py", line 32, in server_error
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     t = loader.get_template(template_name) # You need to create a 500.html template.
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 145, in get_template
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     template, origin = find_template(template_name)
[Thu Jan 07 09:10:12 2016] [error] [client ::1]   File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 138, in find_template
[Thu Jan 07 09:10:12 2016] [error] [client ::1]     raise TemplateDoesNotExist(name)
[Thu Jan 07 09:10:12 2016] [error] [client ::1] TemplateDoesNotExist: 500.html

==> /var/log/httpd/access_log <==
::1 - - [07/Jan/2016:09:10:12 +0000] "GET /v3/modules/puppetlabs-apt HTTP/1.1" 500 609 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2"

I'm using pulp 2.7.1 under CentOS 6.7, while my librarian-puppet is v2.2.1.

Initial troubleshooting with bmbouter on IRC hinted that pulp_puppet is not using the same middleware as pulp, as the latter serializes 500 errors (https://pulp.plan.io/issues/1140#note-4).


Related issues

Related to Pulp - Issue #1140: API call to URLs that do not exist cause 500s on RHEL 6CLOSED - CURRENTRELEASE<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>
Related to Puppet Support - Issue #1486: TemplateDoesNotExist exception for '404.html' raised on v3 API endpointCLOSED - WONTFIX<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>

History

#1 Updated by bmbouter almost 5 years ago

  • Priority changed from Normal to High
  • Version changed from 2.7.0 to 2.7.1

I set higher priority because without fixing this, our ability to solve other issues that occur in the /srv/pulp/puppet_forge.wsgi wsgi handler is significantly diminished.

#2 Updated by bmbouter almost 5 years ago

  • Related to Issue #1140: API call to URLs that do not exist cause 500s on RHEL 6 added

#3 Updated by bmbouter almost 5 years ago

To fix this, I propose a ServerError handler be added to the /srv/pulp/puppet_forge.wsgi wsgi environment instead of using the default ServerError handler which looks for the 500.html thus generating the second exception. This new handler would take the 500 exception, serialize it into a JSON representation, and return the serialized version as the response.

Here[0] is an example of the introduction of a 404 handler in platform that is similar. NOTE It's important to use *args and **kwargs on the handler implemented because newer version of Django change the handler signature in backwards incompatible ways. This was done here[1].

[0]: https://github.com/bmbouter/pulp/commit/996e4366742db143b366c6cccab7231ce0da4904
[1]: https://github.com/bmbouter/pulp/commit/996e4366742db143b366c6cccab7231ce0da4904#diff-0f102dc73ff02451924f2fdaa7df179eR117

#4 Updated by bmbouter almost 5 years ago

  • Related to Issue #1486: TemplateDoesNotExist exception for '404.html' raised on v3 API endpoint added

#5 Updated by mhrivnak almost 5 years ago

  • Triaged changed from No to Yes

#6 Updated by lastmikoi almost 5 years ago

I'll try to work on a fix on my spare time, but feel free to take on this issue if you are more familiar with the code base, as my spare time is quite limited.

#7 Updated by bmbouter almost 5 years ago

One easy way to reproduce this would be with a small, temporary modification to the code:

1) Identify a url handled by the /srv/pulp/puppet_forge.wsgi wsgi handler. (note this was just recently moved locations).
2) Identify a Django view that handles a specific HTTP method (i.e. GET).
3) Add a raise Exception('oh no') statement to that view handler (causing a 500 exception to occur)
4) Use httpie to make an API request to that API endpoint and watch the 500 exception reproduce.

#8 Updated by lastmikoi almost 5 years ago

Unable to set up a development environment (vagrant shenanigans) in a timely manner, I've gone ahead and tested directly in my "production" environment to track down the issue.

By setting `DEBUG` and `TEMPLATE_DEBUG` at `True`, I have been able to expose the original exception.

Turns out the issue is caused by a 404 error, much like https://pulp.plan.io/issues/1140
Indeed, the v3 `/modules` endpoint is not implemented in pulp_puppet, and as such fetching `/v3/modules/puppetlabs-apt` causes a 404 error, as this path is nowhere to be found in the `urls.py` file.

#9 Updated by lastmikoi over 4 years ago

I have been able to reproduce this issue as of Pulp 2.8.2, still under CentOS 6.

Like last time, I had this error wrapping a 404 error, which makes https://pulp.plan.io/issues/1486 related.

#10 Updated by bmbouter over 1 year ago

  • Status changed from NEW to CLOSED - WONTFIX

Pulp 2 is approaching maintenance mode, and this Pulp 2 ticket is not being actively worked on. As such, it is being closed as WONTFIX. Pulp 2 is still accepting contributions though, so if you want to contribute a fix for this ticket, please reopen or comment on it. If you don't have permissions to reopen this ticket, or you want to discuss an issue, please reach out via the developer mailing list.

#11 Updated by bmbouter over 1 year ago

  • Tags Pulp 2 added

Please register to edit this issue

Also available in: Atom PDF