text: When you return a dictionary from a handler and supply a fields attribute, the fields that get serialised are invalid.
  You can duplicate this bug using the following code in the provided test case.
  {{{
  !python
  class InvalidFieldBugHandler(BaseHandler): model = CircularA fields = ( 'link', )
  namespace = 'invalid field bug' references = 'invalid field bug' def read(self, request, name): # Get the C object. circular_c = CircularC.objects.get(name=name) # Return a dictionary containing the circular_c model. If the bug # isn't patched then fields will be passed to serialise circular_c, # and the CircualrA object will be returned. return {'result': circular_c}
  }}}
  Here's the fix in resource.py around line 270. {{{
  !python
  emitter, ct = Emitter.get(em_format) # This is a fix for an obscure bug that occurs when the following # conditions are met: # * You have a handler that has a fields attribute. # * You override this handler's read function to return a dict. # * In that dict, you return a model. # As you iterate over the new list, you will end up passing the # wrong set of fields to the _model function. However, passing in # the fields from this handler, as opposed to looking them up # through the namespace is desirable because you may have a regex # that purposefully matches this specific handler. fields = None if isinstance(result, (Model, QuerySet)): fields = handler.fields if is_iterable(result) and hasattr(handler, 'list_fields'): fields = handler.list_fields
  }}}
  - Log in to comment