'GenericForeignKey' object has no attribute 'serialize'

Issue #140 new
created an issue

The culprit is most probably the support for serialization of virtual fields (56a00eb45824).

Unfortunately the GenericForeignKey field in django (I'm using 1.2.1) doesn't mimic an actual field so many of the common attributes like 'rel', 'attname', 'serialize', etc. are missing.



  1. return _any(self.data, self.fields) File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _any
  2. ret = _dict(thing, fields) File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _dict
  3. return dict([ (k, _any(v, fields)) for k, v in data.iteritems() ]) File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _any
  4. ret = _qs(thing, fields=fields) File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _qs
  5. return [ _any(v, fields) for v in data ] File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _any
  6. ret = _model(thing, fields) File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _model
  7. ret[model] = _model(inst, fields) File "/home/jono/work/sites/labinventory/labinventory/../labinventory/extra/piston/emitters.py" in _model
  8. if f.serialize and not any([ p in met_fields for p in [ f.attname, f.name ]]):

Exception Type: AttributeError at /api/js/f5assets/platform/ Exception Value: 'GenericForeignKey' object has no attribute 'serialize' }}}

Comments (16)

  1. Anonymous

    The other option is to monkey patch the GenericForeignKey object. Something like:

    from django.contrib.contenttypes.generic import GenericForeignKey
    GenericForeignKey.serialize = None

    worked for me.

  2. nanonyme

    Might as well make a try except with AttributeError for the serialize call instead of going through hasattr(). This is what hasattr() essentially does anyhow.

  3. Log in to comment