Fixed #19547 -- Caching of related instances.

When &'ing or |'ing querysets, wrong values could be cached, and crashes
could happen.

Thanks Marc Tamlyn for figuring out the problem and writing the patch.
Minor fixes in the known_related_objects tests.

* Fixed JSON indentation.
* Avoided relying on implicit ordering.