Developer Guide on Upgrading Apps for Hue 3.8

Developer Guide on Upgrading Apps for Hue 3.8

The upcoming Hue 3.8 internals have gone through some major upgrades to improve performance, robustness, and security. The major change stems from upgrading Django from 1.4.5 to 1.6.10, which comes with a significant amount performance enhancements, bug fixes, and the removal of deprecated features.

This post details how Hue developers that are building against the Hue SDK can upgrade their applications to work with Hue 3.8.

django-logo-positive

Python version

Python 2.6.5 is now the minimum version, 2.6.0 is not enough anymore.

Django Upgrade

Hue was upgraded from Django 1.4.5 to Django 1.6.10. While the Django release notes for 1.5 and 1.6 go into extensive detail on how to upgrade, here are the main issues we encountered while upgrading Hue.

Json

We backported Django 1.7’s JsonResponse to simplify responding with Json records. So views that used to be written as:

def view(request):
    value = { “x”: “y” }
    HttpResponse(json.dumps(value))

Can now be written as:

def view(request):
    value = { “x”: “y” }
    return JsonResponse(value)

One thing to note though is that Django now by default will raise an error if a non-dictionary is serialized. This is to prevent against attack against older browsers. Here is how to disable this error:

def view(request):
    value = [“x”, “y”]
    return JsonResponse(value, safe=False)

We recommend that developers migrate over to returning objects. Hue itself should be completely transitioned by 3.8.0.

Urls and Reverse

Django’s django.core.urlresolvers.reverse (and therefore the url function in mako scripts) now automatically escapes arguments. So so uses of these functions should be changed from:

<a href="${ url('useradmin.views.edit_user', username=urllib.quote(user.username)) }">...</a>

To:

<a href="${ url('useradmin.views.edit_user', username=user.username) }">...</a>

StreamingHttpResponse

In order to return a generator from a view, it is now required to use StreamingHttpResponse. When testing, change code from

 csv_response = self.c.post(reverse('search:download'), {
         'csv': True,
         'collection': json.dumps(self._get_collection_param(self.collection)),
         'query': json.dumps(QUERY)
 })
csv_response_content = csv_response.content

To:

csv_response = self.c.post(reverse('search:download'), {
        'csv': True,
        'collection': json.dumps(self._get_collection_param(self.collection)),
        'query': json.dumps(QUERY)
 })
csv_response_content = ''.join(csv_response.streaming_content)

 

Static Files

As described in NGINX-post, Hue now can serve serves static files with a separate webserver like NGINX. This can substantially cut down the number of requests that the Hue frontend needs to perform in order to render a page:

without-nginx with-nginx

This change will break applications using the old way of serving static files. It will also cause conflicts to any user back porting patches that touch static files from Hue 3.8.0 and above to older versions of Hue.

In order to make the transition, do:

  • Move static files from <code>/apps/$name/static</code> to <code>/apps/$name/src/$name/static</code>
  • Update <code>.mako</code> files to change from:
    <link rel=”stylesheet” href=”/metastore/static/css/metastore.css”>

    To:

    <link rel=”stylesheet” href=”${ static(‘metastore/css/metastore.css’) }”>
  • Update the “ICON” in apps/$name/src/help/settings.py from:
    ICON = “/help/static/art/icon_help_24.png”
    

    To:

    ICON = “help/art/icon_help_24.png”
    
  • Update any Python python templates from:
    def view(request):
        data = {‘image’: “/help/static/art/icon_help_24.png”}
        return render(“template.mako”, request, data)
    

    To:

    from django.contrib.staticfiles.storage import staticfiles_storage
    
    …
    
    def view(request):
        data = {‘image’: staticfiles_storage.url(“/help/static/art/icon_help_24.png”) }
        return render(“template.mako”, request, data)
    

Finally, in order to run Hue with debug=False, it is now required to first run either make apps or ./build/env/bin/hue collectstatic in order to gather all the files into the build/static directory. This is not necessary for debug=True, where hue will serve the static files directly from the /apps/$name/src/$name/static directory.

 

Next!

Django 1.8 was released this month! This is the second LTS release and 1.4 support will drop in 6 months. The major dependencies of 1.8 is that it would require Python 2.7, which is not the default Python version on older LTS OS still used nowadays.

 

As usual feel free to comment on the hue-user list or @gethue!

3 Comments

  1. Pooja 3 years ago

    When is 3.8 release coming?

    • Hue Team 3 years ago

      Shortly, in a couple of weeks! Stay tuned for the official release message!

Leave a reply

Your email address will not be published. Required fields are marked *

*