Marketplace/TastypieConversion

From MozillaWiki
Jump to: navigation, search
Stop (medium size).png
The Marketplace has been placed into maintenance mode. It is no longer under active development. You can read complete details here.

We've decided to move from Tastypie to Django Rest Framework.

An initial PR that does this for solitude is here:

https://github.com/mozilla/solitude/pull/94

The goal here is to allow the gradual conversion over to Django Rest Framework (DRF), rather than rewriting it all in one go. Although someone could if they wanted to.

Things that are good

  • DRF seperates everything out - serializers from the resource that renders, paginator and the like. This makes an initial switch look longer in terms of code, but should be more maintainable long term. See the Transaction resource for an example.
  • DRF makes a simple view that just returns some JSON really easy. See the services code for an example.

Things that are challenging

  • There's some code that is complicated because Tastypie made it so. It's still complicated now and you need to take some time if you are going to do things out of the ordinary in Tastypie.
  • Linking between DRF and Tastypie is a pain.

Things that are not backwards compatible

  • DRF sanely reports form errors. I left that alone, no-one should be depending upon that.
  • DRF sanely bubbles up errors to the handler500, I altered that to output some JSON. But in some situations you might get a different formatting of the error from tastypie.
  • DRF has a different URL handler for views, so you there's some fields that do the compatibility. See solitude/base.py > CompatToOneField and CompatRelatedField
  • DRF uses FQDN for its URLs. Tastypie didn't. To maintain backwards compatibility, I monkey patched in not using FQDN. Monkey patching is fragile so keep an eye out for that breaking.
  • DRF has a different paginator. I made the paginator as compatible as possible. But offset and limit does not work the same. I don't expect anyone to use that, but instead to use *prev* and *next*. Those still work.