Developer Guide on Upgrading Apps for Hue 3.8

Published on 08 April 2015 in Development - 3 minutes read - Last modified on 19 April 2021

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.

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:

...

To:

...

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:

<td>
  <a href="https://cdn.gethue.com/uploads/2015/03/with-nginx.png"><img class="aligncenter wp-image-2338" src="https://cdn.gethue.com/uploads/2015/03/with-nginx.png" /></a>
</td>

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 /apps/$name/static to /apps/$name/src/$name/static

  • Update .mako files to change from:

    To:

  • 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!


comments powered by Disqus

More recent stories

26 June 2024
Integrating Trino Editor in Hue: Supporting Data Mesh and SQL Federation
Read More
03 May 2023
Discover the power of Apache Ozone using the Hue File Browser
Read More