The last few days have been really helpful for getting a feel of how 2.0 actually stands up to real world usage, I'd I've been trying to concentrate on tightening up some of the potentially difficult areas, specifically the serialization and related fields.
One thing I've noticed quite quickly is that I tend to find myself having to stop and think before I write a bit of code that initializes a Serializer.
To recap from the docs, that'll typically look something like this:
serializer = AlbumSerializer(instance=album) # retrieve
serializer = AlbumSerializer(instance=queryset) # list
serializer = AlbumSerializer(request.DATA, instance=album) # update
serializer = AlbumSerializer(request.DATA) # create
I made the choice about the ordering of the 'data' and 'instance' arguments the way I did because it mirrors the Forms API - `instance` is actually pretty much the same as `initial`.
In actual usage, this doesn't feel totally natural to me, and I've been thinking that it might not be quite right.
To my eyes at least, the following feels much more natural.
serializer = AlbumSerializer(album) # retrieve
serializer = AlbumSerializer(queryset) # list
serializer = AlbumSerializer(album, data=request.DATA) # update
serializer = AlbumSerializer(data=request.DATA) # create
It's a little different from the Forms API, but then the usage and context *is* a little different. With serializers, the common case is one of the first two,
many APIs won't even use the update or create cases anywhere. Conversely Forms are used exclusively for presenting instances when creation or editing *is* a possibility.
In any case, the upshot is that the later set of operations feel much nicer to me, and also mean that the slightly horrible 'instance' keyword argument (which may in fact be an instance or iterable of instances) is no longer present. The problem of course is that there's no way to make this change without introducing a big backwards incompatible change.
I'm wondering, given how recently released 2.0 is, if I can get away with making this change (with an accompanying big bold warning and explanation in the release notes) on the basis that it'll be worth it in the long run. (I'm hoping that 2.x is going to be with us for a long time)
I also imagine that quite a few folks will simply be using the default generic views, so this wouldn't affect them.
Still, I need the outside perspective. What do you folks think - is this a change worth making and is it okay to be breaking compatibility in this way for the sake of future usability. (Of course I'm slightly kicking myself for not considering this more fully prior to launching 2.0, but things were pretty manic.)
Cheers,
Tom