magopian / django-data-exports

Model data exports for Django
http://django-data-exports.rtfd.org
BSD 3-Clause "New" or "Revised" License
39 stars 12 forks source link

'SingleRelatedObjectDescriptor' object has no attribute 'field' #4

Closed kennknowles closed 11 years ago

kennknowles commented 11 years ago

Hi there,

I'm taking this library for a test drive, and hit this snag:

File ".../python2.7/site-packages/data_exports/forms.py" in add_fields
  41.         choices = get_choices(model)
File ".../python2.7/site-packages/data_exports/forms.py" in get_choices
  58.         choices += get_choices(related_model, prefixes=new_prefixes)
File ".../python2.7/site-packages/data_exports/forms.py" in get_choices
  58.         choices += get_choices(related_model, prefixes=new_prefixes)
File ".../python2.7/site-packages/data_exports/forms.py" in get_choices
  54.         related_model = getattr(model, f).field.rel.to

Exception Type: AttributeError at /admin/data_exports/export/1/
Exception Value: 'SingleRelatedObjectDescriptor' object has no attribute 'field'

I don't have a minimal distilled example, but I can give very simple steps to reproduce:

Environment is Python 2.7, Django 1.5.1, django-data-exports 0.4

  1. pip install django-data-exports
  2. Add data_exports to INSTALLED_APPS
  3. Add the URLs from the docs to urls.py
  4. Go to the admin and
    1. Add a format for csv using data_exports/export_detail_csv.html
    2. Add an export with this format

Now whenever I go to the detail page of that export, I get the above error.

I've browsed the relevant Django code, but I'm afraid I could not isolate the problem.

kennknowles commented 11 years ago

Just confirmed that this still occurs with a clone of the latest.

magopian commented 11 years ago

Hello @kennknowles and thanks a lot for this ticket. It seems somehow related to the first issue in the ticket #3.

Could you please show me which model you're exporting, and which column?

Thanks!

I have the feeling this is actually an issue with django-inspect-model, but I have no proof yet, nor a way to reproduce the issue!

magopian commented 11 years ago

Hello @kennknowles, I believe I found the issue ;)

Can you please confirm that the issue was for a model being pointed to by another one via a OneToOneField?

The latest trunk version should fix your issue in this case, and I'll publish a new version on PyPI in a few days.

aschriner commented 11 years ago

I have the same error. Same steps to reproduce. Model fields in question are:

[<django.db.models.fields.AutoField: id>, <django.db.models.fields.DateTimeField: submission_datetime>, <django.db.models.fields.FloatField: duration>, <django.db.models.fields.related.ForeignKey: user>, <django.db.models.fields.CharField: platformid>, <django.db.models.fields.BooleanField: is_gold_standard>, <django.db.models.fields.TextField: gold_reasoning>, <django.db.models.fields.related.ForeignKey: task_model>, <django.db.models.fields.IntegerField: task_id>, <django.db.models.fields.CharField: clear_view>, <django.db.models.fields.CharField: windows_open>, <django.db.models.fields.IntegerField: how_many>]

I have a ForeignKey to ContentType and an id field that together form a GenericForeignKey. I'm taking a wild guess that maybe that exotic field type is causing the problem?

kennknowles commented 11 years ago

Sorry for the lack of reply for a bit. I still haven't carved out the time to check that this solves it. I am still tracking this, though.

kennknowles commented 11 years ago

This does seem to have solved it. Thanks.

kennknowles commented 11 years ago

Can you please leave a comment here when this has been released to pypi?

magopian commented 11 years ago

wow, this took much longer than I thought, sorry for the delay ;) It's now released (version 0.5 on PyPI)

kennknowles commented 11 years ago

Lovely, thanks!