Fix infinite recursion when serializing object loops.

Review Request #6095 — Created July 10, 2014 and submitted — Latest diff uploaded

Information

Djblets
master
e0cec5a...

Reviewers

If two objects reference each other, and the relevant fields are listed in the
'expand' parameter, the serialization of the response would get a recursion
depth RuntimeError and return 500. This manifested in Review Board using the
"Depends On" field, with two review requests that referenced each other.

I've added some code to make each resource name in "expand" apply only once
for the entire serialization. This makes it possible to still expand deep into
object trees, but prevents infinite loops. To expand multiple levels with the
same resource name, it can be listed twice in 'expand'.

  • Tested setting a review request's "Depends On" to itself.
  • Tested a loop of two objects in "Depends On".
  • Tested recursing multiple levels via:
    curl /api/review-requests/1/?expand=depends_on,depends_on | python -mjson.tool